Storing Data From a For Loop

5 次查看(过去 30 天)
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

采纳的回答

TADA
TADA 2020-6-2
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by