Storing Data From a For Loop

5 views (last 30 days)
Faris Amzar Mohamad Azrai
Commented: TADA on 4 Jun 2020
How can I store all the results from the Loop? I keep getting the final value only.
D_c = 1:1:80;
L_c = 120;
C_s1c = 2.5e6;
C_01c = 2e6;
x = linspace(0,120,100);
xi = 0.1;
precision = 0.0001;
dc = 0;
my_root = [];
for i = 1:length(D_c)
dc = D_c(i);
df_c = @(x) (2.*x * C_s1c)./(2*sqrt(dc^2 + x.^2))-C_01c;
df_c2 = @(x) (dc^2 .* C_s1c)./((x.^2 + dc^2).^1.5);
[root] = newraph(df_c, df_c2, xi, precision);
end

Accepted Answer

TADA
TADA on 2 Jun 2020
Assuming your Newton-Raphson method returns a scalar:
D_c = 1:1:80;
L_c = 120;
C_s1c = 2.5e6;
C_01c = 2e6;
x = linspace(0,120,100);
xi = 0.1;
precision = 0.0001;
dc = 0;
my_root = [];
root = zeros(size(D_c));
for i = 1:length(D_c)
dc = D_c(i);
df_c = @(x) (2.*x * C_s1c)./(2*sqrt(dc^2 + x.^2))-C_01c;
df_c2 = @(x) (dc^2 .* C_s1c)./((x.^2 + dc^2).^1.5);
root(i) = newraph(df_c, df_c2, xi, precision);
end

More Answers (0)

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!