Vector input to function handle for bvp4c
Mostrar comentarios más antiguos
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
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
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
el 22 de Mzo. de 2022
Respuestas (1)
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!
Categorías
Más información sobre Boundary Value Problems en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!