Nested For Loop/Newton Raphson
Show older comments
I am trying to run carry out the Newton Raphson method for a series of Area Ratios in relation to Wind Tunnel experiments. x0 is an initial guess and the AR is an array of 25 area ratios. The method will converge on a solution. I need the for loop to run through all of the area ratios and calculate an X value for each, and return this in the array M for each ratio. Unfortunately I cant get this to work and will just repeat the same X value for all of the ratios at the end. Does anyone have any ideas how I could fix this?
x0 = 1.5; %x0 represents Mach Number Initial Guess
AR = [1.8652 1.5472 1.3327 1.1793 1.0827 1.0258 1.0016 1.0302 1.1091 1.1898 1.2653 1.3334 1.392 1.4389 1.4759 1.5044 1.5249 1.5376 1.5467 1.5547 1.5626 1.5704 1.5783 1.5862 1.5941]
f = @(x0) ((((5/6)+((1/6)*(x0^2)))^3))-(x0*AR);
df = @(x0)((x0))*(((5/6)+((1/6)*(x0^2)))^2)-AR;
M = [];
for i=AR
for i=1:10
x1 = x0 - f(x0)/df(x0);
x0 = x1;
disp(x1)
end
M=[M,(x1)];
end
Answers (1)
x0 = 1.5; %x0 represents Mach Number Initial Guess
AR = [1.8652 1.5472 1.3327 1.1793 1.0827 1.0258 1.0016 1.0302 1.1091 1.1898 1.2653 1.3334 1.392 1.4389 1.4759 1.5044 1.5249 1.5376 1.5467 1.5547 1.5626 1.5704 1.5783 1.5862 1.5941]
f = @(x0) ((((5/6)+((1/6)*(x0.^2))).^3))-(x0.*AR);
df = @(x0)((x0)).*(((5/6)+((1/6)*(x0.^2))).^2)-AR;
for k=1:length(AR)
x1 = x0 - f(x0)./df(x0);
x0 = x1;
disp(x1);
M{k}=x1;
end
M.'
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!