Storing Data From a For Loop

1 vue (au cours des 30 derniers jours)
Faris Amzar Mohamad Azrai
Faris Amzar Mohamad Azrai le 2 Juin 2020
Commenté : TADA le 4 Juin 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

Réponse acceptée

TADA
TADA le 2 Juin 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
  2 commentaires
Faris Amzar Mohamad Azrai
Faris Amzar Mohamad Azrai le 2 Juin 2020
Thanks! It helps alot
TADA
TADA le 4 Juin 2020
cheers

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by