How to use ode() solver
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
Hello, I have following code:
ftod_sym=detofJac(doy); %here I calculate my symbolic vectorfield ftod_sym which is a function of y1 y2 and t
myfun = matlabFunction(ftod_sym); %conversion
[T N]=ode15s(@(y,t)myfun,tspan,n0,optionsO); % n0 is a vector with 2 elements
I get following ERROR:
Error using odearguments (line 93)
@(Y,T)MYFUN returns a vector of length 1, but the length of initial conditions vector is 2. The vector returned
by @(Y,T)MYFUN and the initial conditions vector must have the same number of elements.
Error in ode15s (line 149)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in flipflop_NR (line 46)
[T N]=ode15s(@(y,t)myfun,tspan,n0,optionsO);
Thank You
0 件のコメント
回答 (1 件)
Walter Roberson
2012 年 6 月 24 日
[T N]=ode15s(myfun,tspan,n0,optionsO);
You were not passing y and t to myfun, so you were not getting back the output you were expecting.
5 件のコメント
John Miller
2012 年 6 月 24 日
Walter Roberson
2012 年 6 月 24 日
Looks like you split your y into two arguments instead of treating it as a vector. Easy to account for:
[T N]=ode15s( @(t,y) myfun(t, y(1), y(2)), tspan, n0, optionsO);
John Miller
2012 年 6 月 24 日
Walter Roberson
2012 年 6 月 24 日
Use subscripting of "y" right in your symbolic expression, and then just use myfun as the function handle.
John Miller
2012 年 6 月 24 日
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!