Storing Data From a For Loop

조회 수: 4 (최근 30일)
Faris Amzar Mohamad Azrai
Faris Amzar Mohamad Azrai 2020년 6월 2일
댓글: TADA 2020년 6월 4일
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
  댓글 수: 2
Faris Amzar Mohamad Azrai
Faris Amzar Mohamad Azrai 2020년 6월 2일
Thanks! It helps alot
TADA
TADA 2020년 6월 4일
cheers

댓글을 달려면 로그인하십시오.

추가 답변 (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