Can we solve ODEs as a nested function while using pdepe?

Hi,
I would like to know how to solve ODEs as a nested function or some other way in my pdepe scripts? So lets say this below:
function [c,f,s] = pdex1pde(x,t,u,DuDx)
c = pi^2;
f = DuDx;
s = 0;
end
How do I add a nested function to alter the source s? I know I can do it within the function above as well but I would like to make a more complex function elsewhere and introduce it at s as a sum or subtraction.
Hope I am making some sense.

5 件のコメント

Torsten
Torsten 2022 年 7 月 14 日
Call a function within pdex1pde:
s = fun_s(...)
Hashim
Hashim 2022 年 7 月 14 日
So, I guess you mean to say do something like:
function [c,f,s] = pdex1pde(x,t,u,DuDx)
c = pi^2;
f = DuDx;
s = p;
function p = fun_s(t, y)
p=y(1)*y(2);
[t,y]=ode15s(fun_s, tspan, y0);
end
end
But isn't something like this possible?
function [c,f,s] = pdex1pde(x,t,u,DuDx)
p = fun_s(t, y)
c = pi^2;
f = DuDx;
s = p;
end
function p = fun_s(t, y)
p=y(1)*y(2);
[t,y]=ode15s(fun_s, tspan, y0);
end
Torsten
Torsten 2022 年 7 月 14 日
Please state the equations you are trying to solve.
As it seems, you want to solve an ODE in each grid point of the PDE and assign the solution of this ODE to "s".
But what inputs of the PDE are needed to solve the ODE ?
Hashim
Hashim 2022 年 7 月 15 日
編集済み: Hashim 2022 年 7 月 15 日
Inputs required to solve the ODE are given within the parent function. And yes I just want a separate function to solve the ODE at the grid point. Then add or subtract that solution from s.
The system of equations is given here. Now I have been able to solve these what I am thinking is if I want to add/subtract another source term I want to be able to do it as a separate nested function within the script.
Torsten
Torsten 2022 年 7 月 15 日
From pdex1pde, call a function in which you provide the necessary data to solve the ODE, solve the ODE and return the result to pdex1pde. What's the problem ? And where is the ODE in the set of equations you gave the link to ?

サインインしてコメントする。

カテゴリ

製品

リリース

R2017a

質問済み:

2022 年 7 月 14 日

コメント済み:

2022 年 7 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by