Vector input to function handle for bvp4c

Hi,
I am trying to solve system of equations with bvp4c
res = @(y,res) [D_constant*(res(1)-res(2)); (U_numeric-(D_constant*(res(1)-res(2))))/C_constant; res(3);res(4)];
bc2 = @(T0,TH)[TH(3); TH(4);T0(1);T0(2)];
solinit= bvpinit(y_mesh, [1 0 1 0]);
sol2 = bvp4c (res,bc2,solinit);
In the function handle part; U_numeric is a vector with a dimension of (1 X number of meshes) which is solved before with another bvp4c.
In the res function handle, I want function handle to take U_numeric at corresponding location of y.(not a constant value). U_numeric is also dependent of y only (which is solved separately). How can i achieve this?
To be more specific, I have the solution of U_numeric which contains numbers at each position. Res is also a function dependent to position. I want U_numeric to correctly placed in res function handle to attain correct values for res
Thank you in advance

4 comentarios

Walter Roberson
Walter Roberson el 16 de Mzo. de 2022
If U_numeric is a vector with dimension 1 x number of meshes, then what size of value should the res function handle be returning?
In the second sub-expression, where you are using U_numeric, should U_numeric(K) still be computed based on res(1)-res(2) or should it be computed based on res(K)-res(K+1) ? (And if so, how do you want to handle that you would only be able to use U_numeric(1:number_of_meshes-1) if you were using adjacent res entries?)
Oguz Altunkas
Oguz Altunkas el 16 de Mzo. de 2022
Hello,
res is another function handle which is actually dependent on U_numeric. So, I would like to put U_numeric into res function in such a way that, when res is solved with bvp4c, the value of U_numeric at every y point where res is being calculated is assigned from the vector
For example if res is being computed at y=1; I want U_numeric(y=1) to be in the equation
if res is being computed at y=2; I want U_numeric(y=2) to be in the equation
At the end, I want the domains of U_numeric and res to be the same. Since U_numeric is an independent ODE; it is solved before hand and we have the solution for every y points in the mesh.
Hence, If I can correctly plug the U_numeric into res function handle that takes the value of it at correct y points; the coupled ODE can be solved.
Torsten
Torsten el 16 de Mzo. de 2022
Editada: Torsten el 16 de Mzo. de 2022
You should solve both models simultaneously - the one you get the data from in Unumeric and the one you are asking for.
Oguz Altunkas
Oguz Altunkas el 22 de Mzo. de 2022
But, U_numeric is independent from other parameters it can be solved by itself.
Output of U_numeric is a vector with a dimension of 1x number of meshes.
However, the res function is dependent to the variable of U_numeric. If it was a constnat, the problem could easily be solved. What I want is, while using bvp4c, The value of U_numeric, should be taken such as it is value is taken at correct mesh point.
Both res, and U_ numeric have the same domain. But I could not define U_numeric inside the res function in that manner.
To shorten, U_numeric is also function of y and it is known. While res fcn handle being solved with bvp4c, I want to include U_numeric with other constant variables. (Again, U_numeric is solved before and has value for each y respectively)
Do you know how can I accomplish that?

Iniciar sesión para comentar.

Respuestas (1)

SAI SRUJAN
SAI SRUJAN el 31 de En. de 2024
Hi Oguz,
I understand that you are trying to solve a system of equations with 'bvp4c'.
To pass a vector input to a function handle in 'bvp4c', you can use an anonymous function to capture the vector and pass it to the function handle.
Please refer to the following code outline to proceed further :
U_numeric = [1 2 3 4];
res = @(y, res, U_numeric) [D_constant*(res(1)-res(2)); (U_numeric(y)-D_constant*(res(1)-res(2)))/C_constant; res(3); res(4)];
bc2 = @(T0, TH) [TH(3); TH(4); T0(1); T0(2)];
solinit = bvpinit(y_mesh, [1 0 1 0]);
sol2 = bvp4c(res, bc2, solinit);
In this example, I added an extra input 'U_numeric' to the 'res' function handle. Inside the 'res' function handle, 'U_numeric(y)' is used to access the corresponding value of 'U_numeric' at the given 'y' position.You can modify the code outline above to get the exact function handle.
For a comprehensive understanding of the 'bvp4c' function in MATLAB, please refer to the following documentation.
I hope this helps!

Productos

Preguntada:

el 16 de Mzo. de 2022

Respondida:

el 31 de En. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by