6.2
(a) Graphically I calculated the root to 3.56
Matlab:
x = (3:0.001:4);
f_x = @(x) 2*x.^3 - 11.7*x.^2 + 17.7*x - 5;
plot(x,f_x(x));
(b) Using the Fixed-Point iteration method with up to three iterations I received this output:
Output:
3.5353 3.5514 3.5583
Matlab:
%Fixed point iteration
x = 0;
f_x = @(x) (2*x.^3 - 11.7*x.^2 - 5)./-17.7;
sol = f_x(x)
for iter = 1:2
sol = f_x(sol)
end
Output:
3.5672 3.5632 3.5632
Matlab:
%Newton Raphson Method
x = 3;
x = 3;
f_x = @(x) (2*x.^3 - 11.7*x.^2 + 17.7*x -5);
f_px = @(x) (6*x.^2 - 23.4*x +17.7);
sol(1) = x - (f_x(x))/(f_px(x));
for iter = 2:3
x= sol(iter-1);
sol(iter) = x - (f_x(x))/(f_px(x));
x= sol(iter-1);
sol(iter) = x - (f_x(x))/(f_px(x));
end
sol()
(d)Using the Secant method:
Output:
2.7463 2.9326 3.0570
Matlab:
%Secant Method
x = 3;
x_1 = 2;
f_x = @(x) (2*x.^3 - 11.7*x.^2 - 5)./-17.7;
for iter = 1:8
sol(iter) = (f_x(x)*(x_1-x))/(f_x(x_1)-f_x(x));
x_1 = x;
x = sol(iter);
end
sol()
(e)Using the Modified Secant method:
Output:
3.1621 3.4121 3.6067
%Modified Secant Method
x = 3;
Delta = 4;
f_x = @(x) (2*x.^3 - 11.7*x.^2 - 5)./-17.7;
for iter = 1:3
sol(iter) = x-(Delta*x*f_x(x))/(f_x(x+Delta*x)-f_x(x));
Delta = x;
x = sol(iter);
end
sol()
For this problem I just reused the matlab from problem 6.2, 4.2 Gave me a valid Result, however the input of 4.43 did not.
Matlab:
Output:
4.2 : 0.4746
4.43: -0.2280
Matlab:
%Newton Raphson Method
x = 4.2;
f_x = @(x) (-2 + 6*x -4*x.^2 +0.5*x.^3);
f_px = @(x) (1.5*x.^2 -8*x +6);
sol(1) = x - (f_x(x))/(f_px(x));
for iter = 2:8
x= sol(iter-1);
sol(iter) = x - (f_x(x))/(f_px(x));
end
sol()
(b) Using this method(in my Matlab) I was able to execute a modified version of the Newton -Raphson method to calculate the roots of these equations:
Matlab:
%Newton Raphson Method for a non linear system
%u_0 = x^2 +xy - 10= 0
%v_0 = y + 3xy^2 -57 = 0
x = 2;
y = 1.5;
for iter = 1 : 10
u_0 = (-x.^2 + x + 0.75)/y;
v_0 = (y+5*x*y)/x.^2;
du_0x = (1-2*x)/y;
du_0y = (x.^2 - x - 0.75)/y.^2;
dv_0x = -((5*x+2)*y)/x.^3;
dv_0y = (5*x +1)/x.^2;
deter = du_0x*dv_0y - du_0y*dv_0x;
xsol = x - ((u_0*dv_0y - v_0*du_0y)/(deter));
ysol = y - ((v_0*du_0x - u_0*dv_0x)/(deter));
sol1(iter) = xsol;
sol2(iter) = ysol;
x = xsol;
y = ysol;
end
sol1()
sol2()
6.18
For this problem I took the supplied equation and rewrote it as c = ((W-Qc)/kV)^2 and applied my modified secant method with c = 4 and delta = 0.5 and got an Output as follows:
Output:
7.6000 7.3750 7.2394
-0.0305 -0.0187
Matlab:
c = 4;
Delta = 0.5;
V = 1*10^6;
Q = 1*10^5;
W = 1*10^6;
k = 0.25;
f_c = @(c) ((W - Q*c)/k*V)^2;
for iter = 1:3
sol(iter) = c-(Delta*c*f_c(c))/(f_c(c+Delta*c)-f_c(c));
Delta = c;
c = sol(iter);
end
sol()
err(1) = (sol(2)-sol(1))/sol(2)
err(2) = (sol(3)-sol(2))/sol(3)
Using the value of 16.15 will not give you the root between 15 and 20 because 16.15 is lower than the root, so it converges to the next root, 0.468. However if I change the initial guess to lets say 20, the root is found at : 18.8948
Matlab:
%Newton Raphson Method
x = 16.15;
f_x = @(x) (0.0074*x.^4 - 0.284*x.^3 + 3.355*x.^2 - 12.183*x + 5);
f_px = @(x) (0.0296*x.^3 - 0.852*x.^2 + 6.71*x - 12.183);
for iter = 1:9
sol(iter) = x - (f_x(x))/(f_px(x));
x = sol(iter);
end
sol()
No comments:
Post a Comment