How to solve this issue?

1 次查看(过去 30 天)
Hello there,
I got this error when i use ODE15s solver :
Error using odearguments (line 113)
Inputs must be floats, namely single or double.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in simple (line 44)
[T1,cox]=ode15s(@(t,y1) Costatesimple(t,y1,u,x1,x2,yd,x1t,e1,w1,w2,w3,w4,v1,v2),tspan2,[0 0 0 0 0 0 0],options);
any help please?
Note: i used syms in diffrent file to get some parameters and save it as a datafile then load it in Costatesimple file...
thank you so much indeed

采纳的回答

Star Strider
Star Strider 2020-3-21
If the extra parameters (or any other values) you are passing to ‘Costatesimple’ are symbolic, (and do not contain any symbolic variables), it will be necessary to use the double function to convert them to double-precision values that ode15s can use.
  14 个评论
Star Strider
Star Strider 2020-3-23
As always, my pleasure.
I cannot comment because I do not have your code.
Steven Lord
Steven Lord 2020-3-23
Save the following code as example512084.m and try running it. The first ode45 call uses a function (thisWillNotWork) that returns a sym value to ode45 and so that won't work. If you comment out that call and uncomment the second ode45 call, it will work because while thisWillWork uses symbolic calculations internally what it returns to ode45 is a double array.
function sol = example512084
sol = ode45(@thisWillNotWork, [0 5], 1);
% sol = ode45(@thisWillWork, [0 5], 1);
function dydt = thisWillNotWork(~, y)
two = sym(2);
dydt = two*y; % dydt is symbolic
function dydt = thisWillWork(~, y)
two = sym(2);
dydt = two*y; % dydt is symbolic
dydt = double(dydt); % dydt is now double

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by