Error with ode45 when using a decreasing x value: more non-singleton rhs dimensions than non-singleton subscripts

1 回表示 (過去 30 日間)
I am working on a problem in which I use ode45 to estimate an equation as x goes from 8 to .0, using 78 steps of the size .1. Y is increasing as x decreases.
The equation is: function f=fun2(t,y) f=('-(sqrt(100-t^2)/(t))')
I used a linspace to hold the step values: p=linspace(8,0.2,78)
With the initial y value to be 6, I set it all up as:
[x,y]=ode45('fun2',p,6)
However, I am consistently getting this error:
"Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in ode45 (line 184) k_(:,1)=feval(FUN,t,x); % first stage"
What am I doing wrong, and how can I fix this? I am quite new to Matlab, and am not sure what to do.

採用された回答

Torsten
Torsten 2018 年 2 月 26 日
編集済み: Torsten 2018 年 2 月 26 日
function main
tspan=linspace(8,0.2,78);
y0=6;
[t,y]=ode45(@fun2,tspan,y0)
function f = fun2(t,y)
f=-sqrt(100-t^2)/t;
end
Best wishes
Torsten.

その他の回答 (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