フィルターのクリア

Unable to assign a vpasolve result from a for loop

5 ビュー (過去 30 日間)
Rihards
Rihards 2022 年 10 月 26 日
コメント済み: Rihards 2022 年 10 月 26 日
Hello there,
It's been a little while since I last used matlab extensively and this little error here has been driving me nuts for hours now.
I have a very simple script that runs a for loop to calculate multiple variables with an end goal of acquiring two arrays for a plot D(i) and H_sol(i), however, the last line with H_sol(i) is giving me an error:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
If I remove the i index, it will run with no problems, so I am a little confused here. Why would it not allow me to have two values of D and H_sol that correspond to the same i value/index?
syms k H0_t3
g=9.81;
omega=0.54
Hb=8
D=0:0.5:110;
for i=1:length(D)
eq1=omega^2==g*k*tanh(k*D(i));
k_var=vpasolve(eq1,k,0.01);
G_var=(2*k_var*D(i))/(sinh(2*k_var*D(i)));
eq2=H0_t3==Hb*sqrt((1+G_var)*tanh(k_var*D(i)));
H_sol(i)=vpasolve(eq2,H0_t3)
end

採用された回答

Torsten
Torsten 2022 年 10 月 26 日
編集済み: Torsten 2022 年 10 月 26 日
For D = 0, there is no solution for k. And why do you solve for H0_t3 ? If Hb does not depend on H0_t3, the equation for H0_t3 is already explicitly solved for this variable.
  3 件のコメント
Torsten
Torsten 2022 年 10 月 26 日
編集済み: Torsten 2022 年 10 月 26 日
By setting
D = 0.5:0.5:110;
And still the question: Why do you solve for H0_t3 ?
H0_t3 = Hb*sqrt((1+G_var)*tanh(k_var*D(i)));
and all the variables on the right-hand side are known.
Rihards
Rihards 2022 年 10 月 26 日
.. must have been too focused on the wrong problem there. Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeneral Applications についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by