Vector input to function handle for bvp4c

5 visualizzazioni (ultimi 30 giorni)
Oguz Altunkas
Oguz Altunkas il 16 Mar 2022
Risposto: SAI SRUJAN il 31 Gen 2024
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 Commenti
Torsten
Torsten il 16 Mar 2022
Modificato: Torsten il 16 Mar 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 il 22 Mar 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?

Accedi per commentare.

Risposte (1)

SAI SRUJAN
SAI SRUJAN il 31 Gen 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!

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by