How to solve a differential equation with two unknown variables
Afficher commentaires plus anciens
Hello Matlab community,
I would like to solve the following differential equation of u(y,t):
I've written so far:
function du=func(t,y,u)
du(1,1)=u(2);
du(2,1)=diff(u,t);
[[t y],u]=ode45(@([t y],u)func(t,y,u),[0 10],[0 100], [0 15]);
u
end
Am I on the right track?
It shows the following error message:
Error: File: func.m Line: 4 Column: 17
Unbalanced or unexpected parenthesis or bracket.
3 commentaires
Jan
le 14 Juin 2021
You are calling the integrator from inside the function to be integrated. This will cause an infinite recursion.
Matthew Worker
le 16 Juin 2021
It depends on what "outside the function" means and which Matlab version you are using.
In modern Matlab versions, you can define functions on the bottom of a script, but not on top.So simply call the integrator in a line of code above the funcion to be integrated.
An alternative is to use functions, which have some advantaged compared to scripts.
Bu the main problem is, that I cannot guess, what this line of code should do:
[[t y],u]=ode45(@([t y],u)func(t,y,u),[0 10],[0 100], [0 15]);
This is no valid Matlab syntax.
You cannot solve a partial differential equation in this way by ODE45, which is designed for ODEs. So this is not a Matlab problem, but a mathematical one.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!