error about Euler method
2 views (last 30 days)
Show older comments
Hi guys, can anyone hepl me? I have to solve two differential equations with the Euler method. They are V(i+1)=... and gamma(i+1)=...
Thanks.
The ERROR is:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in (line 56)
V(i+1)=V(i)+(((0.5*rho(i)*V(i))/(sin(gamma(i))))*B - g(i)/V(i))*Delta_H;
And the SCRIPT is:
FILE=importdata('FILE.dat',',');
H=FILE.data(:,1))*1000; % [m]
g=FILE.data(:,2); % [m/s^2]
T=FILE.data(:,3); % [K]
rho=FILE.data(:,4); % [Kg/m^3]
P=FILE.data(:,5); % [K/Kmol]
lambda=FILE.data(:,6); % [m]
R_0=6378000;
n=length(H);
V(1)=7500; % [m/s] initial value of V
gamma(1)=convang(1.5,'deg','rad'); %initial value of gamma
for i=1:(n-1)
Delta_H=H(i+1)-H(i);
R=R_0+H(i);
V(i+1)=V(i)+(((0.5*rho(i)*V(i))/(sin(gamma(i))))*B - g(i)/V(i))*Delta_H;
gamma(i+1)=gamma(i)*+(1/(R*(sin(gamma(i)))) ...
-((g(i)/(V(i)^2))*(1/(tan(gamma(i))))))*Delta_H;
end
gamma_deg=convang(gamma,'rad','deg');
figure(1)
plot(V,(H/1000),'k-','Linewidth',1.15)
figure(2)
plot(gamma_deg,(H/1000),'k-','Linewidth',1.15)
0 Comments
Answers (1)
Walter Roberson
on 31 Dec 2020
B is not defined in the code. It has whatever value is left over in the workspace.
3 Comments
Walter Roberson
on 2 Jan 2021
The cause of the error is that B is not a scalar at the time the problem occurs.
dbstop if error
run the code. When it stops examine the size of B and then the size of each of the subexpressions.
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!