I am getting Vectors must be the same length error when I tried to plot. I have attached the full Matlab-files.

1 回表示 (過去 30 日間)
zspan=[0,400];
w0=0.1;
b=1;
gmark=1;
y0=[b*b*w0; b*b*w0*w0; b*b*w0*gmark];% Initial values
options=odeset('RelTol',1e-6,'AbsTol',1e-6,'Events',@stopevents);
sol=ode45(@rhs,zspan, y0,options);
sol.mssflx=sol.y(1,:);
sol.vel=sol.y(2,:)./sol.mssflx;
sol.gmark=sol.y(3,:)./sol.mssflx;
sol.b=sqrt(sol.mssflx./sol.vel);
sol.mntflx=sol.mssflx.*sol.vel;
sol.bncyflx=sol.mssflx.*sol.gmark;
figure(1)
plot(sol.vel,zspan)
%%%%%
function dy=rhs(z,y)
% Calculate rho and N2(z)
[rho, Nsqr]=density1(z);
% Calculate entrainment
alpha=0.116;
massflux=y(1);
velocity=y(2)/massflux;
gmark=y(3)/massflux;
fric= 1*velocity*abs(velocity);
b=sqrt(massflux/velocity);
dy(1)=2*alpha*b*velocity;
dy(2)=b*b*gmark- fric;
dy(3)=-massflux*Nsqr;
dy=dy';
end

採用された回答

Matt J
Matt J 2018 年 2 月 8 日
編集済み: Matt J 2018 年 2 月 8 日
In,
plot(sol.vel,zspan)
zspan only has two numbers in it. sol.vel has more. So, they cannot be sensibly plotted together.
  4 件のコメント
Dereje
Dereje 2018 年 2 月 8 日
I am getting this error : Undefined function 'sign' for input arguments of type 'logical'.
Walter Roberson
Walter Roberson 2018 年 2 月 8 日
stopevents needs to return a numeric value, not a logical. Confusingly, the numeric value should be less than or equal to 0 to signal continuation, and greater than 0 to signal termination.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by