error: 'Inputs must be floats, namely single or double' while trying to solve an ODE having an unknown coefficient.
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ASHU JAGLAN
el 14 de En. de 2021
Comentada: Walter Roberson
el 14 de En. de 2021
I am trying to solve the given problem using ode45.
x'' + a x' + 7.9( x^3) = 3.2 sin(xt), and x(0) = 1.2, x'(0) = −3.3, and x(2.3) = −0.6
In this i have to find possible values of a for which x(2.3)=-0.6
Now i am trying to get a symbolic expression in a for which x(2.3) = f(a)
from this i will get an expression for a which can be solved to get possible possible values of a for which f(a) = -0.6.
Now i have written a matlab code to get this expression but matlab returns an error 'Inputs must be floats, namely single or double'
i am not sure whether ode45 can be used to get an expression for x(t) containg an unknown a. Please suggest the changes in the code below
this is the first .m file:
function pdot=func4(t,q)
pdot=sym(zeros(size(q)));
syms a;
pdot(1)=q(2);
pdot(2)=3.2*sin(q(1)*t)-a*q(2)-7.9*((q(1))^3);
end
second .m file
x0=[1.2 -3.3];
tspan=0:0.1:2.5;
opts = odeset('RelTol',1e-12,'AbsTol',1e-12);
[t,x]=ode45('func4',tspan,x0,opts);
fprintf(x(:,1));
after running the second .m file i get this error
Error using odearguments (line 113)
Inputs must be floats, namely single or double.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in odeforty_five (line 4)
[t,x]=ode45('func4',tspan,x0,opts);
0 comentarios
Respuesta aceptada
Walter Roberson
el 14 de En. de 2021
The function you call for ode*() is permitted to use symbolic expressions internally, but the return value must be completely numeric. Even returning a sym form of a number is not permitted: only double or single.
ode45 is completely numeric and cannot be used to return a symbolic expression.
You will need to use a completely different approach.
Potentially dsolve() might work for you... but probably not.
If dsolve() does not work for you then you have a Boundary Value Problem and should use bvp4c or similar routines.
2 comentarios
Walter Roberson
el 14 de En. de 2021
It is not possible to solve this task using ode45 command only. It is potentially possible to solve it using ode45 and "the shooting method" (basically, a binary search). See http://www.mathworks.com/help/matlab/math/parameterizing-functions.html for how you can pass a trial numeric a value into the function.
Más respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!