Unable to assign a vpasolve result from a for loop

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by