Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Generate and solve differential equation? Please suggest some better way if you know.

1 vue (au cours des 30 derniers jours)
P K
P K le 30 Déc 2018
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hello everyone, I am working on a project and i have to deal with many of differential equations. I am able to generate those differential equations through MATLAB. But, the problem is TIME. It takes a lot of time. Hence I want to save these differential equations in my first run. Then call these differential equations when i need. This would save time in generating the differential equation each time I run my main file.
The variable "n" determines the number of differential equations.AS n Increases, the number of differential equation would be large.
Suppose n=3,there would be four equations generated.
Eqn =[(3*C(1)^2)/250 - (3*C(1)*C(2))/200;
(3*C(1)^2)/500 - (3*C(1)*C(2))/200;
(3*C(1)*C(2))/1000;
(3*C(1)*C(2))/250]
%Dimension 0f eqn
eqn=4 X 1 sym
%I have tried iT with a function
function [dCondT]=trail6(t,C)
load('diffeqn_n_3') %Saved eqn and loaded here
dCondT=sym(zeros(length(Diff_eqns_of_molecules),1))
for n=1:length(Diff_eqns_of_molecules)
dCondT(n)=[Diff_eqns_of_molecules(n)]
end
end
% then tried solving it with ODE45
ERROR-"Inputs must be floats, namely single or double.
Can anyone help ?
  6 commentaires
madhan ravi
madhan ravi le 30 Déc 2018
Eval is evil see the suggestion below.
P K
P K le 30 Déc 2018
Thanks @all i would not use Eval but for now i am getting my result through Eval.

Réponses (2)

madhan ravi
madhan ravi le 30 Déc 2018
As John D'Errico says you may want to use odetovectorfield() and matlabFunction() to convert your symbolic odes to numeric odes.
  2 commentaires
P K
P K le 31 Déc 2018
@Walter & @ madhan -if i am getting correct solution, what is wrong in using eval() . It is very conveniently giving the result. I have checked the solution to validate the solution

Walter Roberson
Walter Roberson le 30 Déc 2018
You are trying to use ode45 with symbolic equations, which is not possible. See odeToVectorField and odeFunction for routines to convert symbolic differential equations for use with the numeric ode* routines.
  2 commentaires
P K
P K le 30 Déc 2018
I tried using eval with ode45 and i got the result
Walter Roberson
Walter Roberson le 30 Déc 2018
Symbolic expressions are in a language which is not exactly MATLAB. When you eval() a symbolic expression you can get errors -- or even worse, you might not get an error but might encounter a subtle difference. There are some functions for which the parameters mean different things for the numeric function compared to the symbolic function (such as the parameters being in a different order.)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by