How to solve this issue?

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

 Accepted Answer

Star Strider
Star Strider on 21 Mar 2020

0 votes

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 Comments

thank you so much for reply
you mean in symbolic file i have to use double function ?
As always, my pleasure!
Keep the values symbolic in the symbolic part of your code. In the numeric part (the ode15s call) they must not be symbolic, so use the double function to convert them from symbolic to double.
You can use symbolic variables and functions inside your ODE function. The ODE solver doesn't really care what your ODE function does internally (within reason. If you have your ODE function just generate random data, it's going to generate a random solution for example.)
But what your ODE function returns to the ODE solver ode15s must be a single or double array. So just before the end of your ODE function, if the values it would return aren't single or double, use single or double to convert them to the appropriate type.
Alternately use the tools in Symbolic Math Toolbox for solving ODEs instead of ode15s.
ohh understood thank you for your answering sir
can you tell me how to conver to double function i tried many times but i didn't get results
when i run symbolic file i got some parameters how to convert it to double befor go to another file
please i hope to assit me
thanks advance.
I do not understand what you are asking.
The double function will work if you have purely numeric symbolic values. If you have symbolic variables as well, double will not work. All the symbolic variables must have values (so the expression becomes purely numeric) in order to use the double function.
sorry to disturb you sir but all my symbolic are variables when i run symbolic file i want to use these results in symbolic to another file if i make it copy and paste it's works but i need way to passed it without copy and paste due to the equations are so long
thnk you so much indeed
I do not understand.
Consider using the save funciton to save them to a .mat file, then load that .mat file in the code you want to use them in.
i used already but when i load it for examble: load a. mat aw1 a2w1 a3w1 a4w1 a5w1 a6w1 a7w1
and i want to use thsese variables in b.file for examble i got this error (Inputs must be floats, namely single or double).
thank you sir for giving your time to try solve my problem i hope you found my issue. Is there any way to run a.m file and get the results from a.m and use it in b.m file ?
note: a.m file is like this :
syms w1
n=x1*w1
aa=diff(n,w1)
i need to use aa in b.m file
am so grateful to you sir..
i do not understand the problem you are experiencing. If you want to use them as symbolic, the .mat file approach should work. If you want to use them as numeric, they need to be double values. I cannot add anything more than I already have discused. I do not have enough information.
Alright, sir i appreciate that
maybe the problem in call file it should be numeric though, i cannot how to convert to double values.
thank you so much..
As always, my pleasure.
I cannot comment because I do not have your code.
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

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!