How to solve a differential equation with two unknown variables

4 次查看(过去 30 天)
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 个评论
Matthew Worker
Matthew Worker 2021-6-16
When i call the integrator outside the function i get this error message:
This statement is not inside any function.
(It follows the END that terminates the definition of the function "func".)
How can i solve this?
Jan
Jan 2021-6-16
编辑:Jan 2021-6-16
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.

请先登录,再进行评论。

采纳的回答

John D'Errico
John D'Errico 2021-6-16
This is a PDE. A partial differential equation. ODE45 CANNOT solve it, as it is not designed to solve that class of problem. (Note the fragment ODE in ODE45. It is there for a reason.) By the way, the error you got was completely unrelated to the problem with trying to use ODE45. That was just invalid MATLAB syntax, so your code failed long before ODE45 figured out that your problem was not something it is designed to solve. Similarly, dsolve cannot solve that class of differential equation.
So you are NOT on the right track. You need to use a tool designed to solve a parabolic PDE. What you have written is a fairly classical form. You might look at the tool PDEPE. It is designed to solve a PDE of that general family.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by