필터 지우기
필터 지우기

Unable to assign a vpasolve result from a for loop

조회 수: 1 (최근 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 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