Using 'fzero' in a for loop
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I am trying to solve for the roots within a 'for loop', and within the function for which I am root finding, I am using a previously defined variable.
It might make it easier to show my code:
A_Astar_x = zeros(1,IL-1);
Mach_Test = zeros(1,IL-1);
M_x = zeros(1,IL-1);
for i=1:IL-1
A_Astar_x(i) = (y(i,JL)-y(i,1))/(y(1,JL)-y(1,1))*A_A;
Mach_Test(i) = @(set) A_Astar_x(i)-(1/set)*((1+.5*(gamma-1)*set^2)/(.5*(gamma+1))).^alpha;
M_x(i) = fzero(Mach_Test(i),.2);
end
I get an error message that says:
Conversion to double from function_handle is not possible.
Does this error message mean that I cannot solve for the roots iteratively like this?
If not, does anyone know any other methods to go about this?
Thanks,
Jon
0 件のコメント
採用された回答
Matt J
2021 年 4 月 26 日
編集済み: Matt J
2021 年 4 月 26 日
Do you really need to save the sequences of anything besides the M_x(i)? If not, then,
for i=1:IL-1
A_Astar_x = (y(i,JL)-y(i,1))/(y(1,JL)-y(1,1))*A_A;
Mach_Test = @(set) A_Astar_x-(1/set)*((1+.5*(gamma-1)*set^2)/(.5*(gamma+1))).^alpha;
M_x(i) = fzero(Mach_Test,.2);
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!