Effacer les filtres
Effacer les filtres

Unable to assign a vpasolve result from a for loop

1 vue (au cours des 30 derniers jours)
Rihards
Rihards le 26 Oct 2022
Commenté : Rihards le 26 Oct 2022
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

Réponse acceptée

Torsten
Torsten le 26 Oct 2022
Modifié(e) : Torsten le 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 commentaires
Torsten
Torsten le 26 Oct 2022
Modifié(e) : Torsten le 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 le 26 Oct 2022
.. must have been too focused on the wrong problem there. Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by