Unable to assign a vpasolve result from a for loop

4 views (last 30 days)
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

Accepted Answer

Torsten
Torsten on 26 Oct 2022
Edited: Torsten on 26 Oct 2022
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 Comments
Torsten
Torsten on 26 Oct 2022
Edited: Torsten on 26 Oct 2022
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 on 26 Oct 2022
.. must have been too focused on the wrong problem there. Thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!