(a) Graphically, I approximated the values of the functions at zero to -1.63 and 5.63
Matlab code:
x = (-2:0.01:6);
f_x = @(x) -0.6*x.^2 + 2.4*x + 5.5;
plot (x,f_x(x))
(b) Using the quadratic formula:
I was able to obtain the values at : -1.6286 and 5.6286
Matlab:
Matlab:
a = -0.6;
b = 2.4;
c = 5.5;
quad1 = ((-b + sqrt(b^2 -4*a*c))/(2*a))
quad2 = ((-b - sqrt(b^2 -4*a*c))/(2*a))
(c) Using the bisecting method I got the solution of 5.62
Matlab:
Matlab:
f_x = @(x) -.06*x.^2 +2.4.*x +5.5;
%x lower
x_l = 5
%x upper
x_u = 10
x_r = (x_l * x_u) / 2
for i = 1:3
if ((f_x(x_l))*(f_x(x_u)) < 0)
x_u = x_r;
elseif ((f_x(x_l))*(f_x(x_u)) > 0)
x_l = x_r;
elseif ((f_x(x_l))*(f_x(x_u)) == 0)
break;
end
x_r =(x_l+x_u)/2;
end
5.6
(a) This problem is the same as 5.1. Here is the graphical solution with my approximations at : 1
Matlab:
x = (-2:0.001:2);
f_x = @(x) log(x.^4);
plot (x,f_x(x))
grid on
(b) This is also the same as problem 5.1 and the approximation is = 0.5
Matlab:
x = (-2:0.001:2);
f_x = @(x) log(x.^4);
%x lower
x_l = .5
%x upper
x_u = 2
x_r = (x_l * x_u) / 2
for i = 1:3
if ((f_x(x_l))*(f_x(x_u)) < 0)
x_u = x_r;
elseif ((f_x(x_l))*(f_x(x_u)) > 0)
x_l = x_r;
elseif ((f_x(x_l))*(f_x(x_u)) == 0)
break;
end
x_r =(x_l+x_u)/2;
end
I coded it up in Matlab for three iterations and got these results:
Output:
1st Iteration: 1.2500
2nd Iteration: 1.0674
3rd Iteration: 1.0186
Matlab:
x = (-2:0.001:2);
f_x = @(x) log(x.^4);
%plot (x,f_x(x),'red')
%grid on
x_u = .5;
x_l = 2;
for iter = 1:3
x_r = x_u - (f_x(x_u)*(x_l - x_u))/ (f_x(x_l) - f_x(x_u));
x_l = x_r ;
x_r
end
5.7
(a)To find the root analytically I used Wolfram alpha and got the value 2.6666.....
(b)Graphically I approximated the value to 2.6
Matlab:
x = (-2:0.1:6);
f_x = @(x) (0.8 - 0.3.*x)./x;
plot (x,f_x(x),'red')
grid on
(c)For this part I used the Method of False Position:
I coded it up in Matlab for three iterations and got these results:
Output:
1st Iteration: 2.8750
True error: -0.0781
Approximate error: 0.0435
2nd Iteration: 2.7969
True error: -0.0488
Approximate error: 0.0726
3rd Iteration: 2.7480
True error: -0.0305
Approximate error: 0.0917
Matlab:
x = (-2:0.1:6);
f_x = @(x) (0.8 - 0.3.*x)./x;
x_u = 1;
x_l = 3;
x_rp = x_l;
true = (8/3);
for iter = 1:3
x_r = x_u - (f_x(x_u)*(x_l - x_u))/ (f_x(x_l) - f_x(x_u));
x_l = x_r ;
%true error
err_t(iter) = (((true - x_r)/true)*1);
%approx error
err_a(iter) = abs((((x_r - x_rp)/x_r)*1));
sol(iter) = x_r;
end
sol
err_t
err_a
5.13
For this problem I used the same algorithm from the last few problems to execute the false position method. I kept using different initial values until my approximate error was close to 0.1% which gave me a value of 59.8428.
Matlab:
g = 9.8;
c = 15;
v = 35;
t = 9;
m = (25:1:70);
f_m = @(m) ((g*m)/c).* (1 - exp(-((c./m)*t)))-v;
plot (m,f_m(m));
x_u = 20;
x_l = 60;
x_rpre = x_l;
for iter = 1:5
x_r(iter) = x_u - (f_m(x_u)*(x_l - x_u))/ (f_m(x_l) - f_m(x_u));
x_l = x_r ;
%app error
if (iter > 1)
err_a(iter) = abs(((x_r - x_rpre)/x_r))*1;
end
end
x_r
err_a
5.21
For this problem I simply plugged in the values given and solved the function with Matlab
Matlab:
A = 5500;
n = 6;
P = 25000;
i = (-5:0.1:10);
int = @(i) P* ((i(1+i)^n)/((1+i)^n - 1));
x_u = 1;
x_l = 3;
for iter = 1:3
x_r = x_u - (int(x_u)*(x_l - x_u))/ (int(x_l) - f_x(x_u));
x_l = x_r ;
sol(iter) = x_r;
end
sol
No comments:
Post a Comment