How to fix: Index Exceeds Matrix Dimensions

1 回表示 (過去 30 日間)
Priya M
Priya M 2021 年 8 月 29 日
コメント済み: Priya M 2021 年 8 月 30 日
err: Index Exceeds Matrix Dimensions

採用された回答

Wan Ji
Wan Ji 2021 年 8 月 29 日
Hi, friend
ode45 function outputs a struct with size 1x1 when only one argument is for output data. If you want to output x solution as n*m double matrix use
[t,x] = ode45(...);
Or use
[~,x] = ode45(...);
instead of directly using
x = ode45.....
SO, I modified your code as
clc;
clear all;
t=linspace(0,1,10);
M=0.5;
beta=0.5;
p1=0.1;
p2=0.5;
f=@(t,x) [x(2);x(3);2*x(2).^2+2*(x(2)*x(5))-x(1)*x(3)-x(3)*x(4)+M.^2*x(2)/(1+1./beta);
x(5);x(6);2*x(5).^2+2*(x(2)*x(5))-x(1)*x(6)-x(4)*x(6)+M.^2*x(5)/(1+1./beta)];
err_threshold=1e-3;
iterator =1;
err=1;
while err > err_threshold
if iterator == 1
[~,x]=ode45(f,[0 1],[0 1 p1 0 0.3 0],t);
% ylim([0 5]);
%plot(t,x(:,3),'--')
m1=x(end,3);
%.........................................
[~,x]=ode45(f,[0 1],[0 1 p2 0 0.3 0],t);
m2=x(end,3);
plot([p1 p2],[m1 m2]);
else
p2=(p2-p1)/(m2-m1)*(1.0-m1)+p1;
[~,x]=ode45(f,[0 1],[0 1 p2 0 0.3 0],t);
m2=x(end,3);
plot([p2,m2]);
err=abs(1-m2);
end
iterator=iterator+1;
end
  1 件のコメント
Priya M
Priya M 2021 年 8 月 30 日
Thanx a lot sir....

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by