Solving coupled equations in Matlab

Hii Friend,
I have set of coupled differential equations which i need to solve and plot using matlab.
I am confused on how to proceed.Do suggest me on how to proceed with it.
The final out needed is a plot of abs(B(1)) Versus delk versus Z as shown in the pic.

 採用された回答

Star Strider
Star Strider 2015 年 1 月 29 日

0 投票

See the documentation on Ordinary Differential Equations.
First, follow the documentation and write your ODE function, then use the appropriate ODE solver (try ode45 first) to integrate it. If you have problems, describe them, completely copying and pasting any error messages that occur, and attach your script and your ODE function files. We will do our best to help you get your code running if you need our help.

16 件のコメント

Pavan Kumar
Pavan Kumar 2015 年 1 月 29 日
編集済み: Pavan Kumar 2015 年 2 月 3 日
Thanks for the suggestion star Strider.
I have written the code for both the function and function calling part.The initial conditions for B1,B2 and B3 are 0.1,0 and 1 respectively. i need to pass delk variable in the ode45 and then make the 3d plot as shown above.I am stuck here.
Star Strider
Star Strider 2015 年 1 月 29 日
編集済み: Star Strider 2015 年 1 月 29 日
My pleasure.
You would pass extra parameters, such as ‘delk’ to your ‘DB’ function as:
function dB = DFG789(Z1,B,delk)
...
then in your ode45 call, define ‘delk’ in your workspace and call your function as:
delk = ...
[Z1,B] = ode45(@(Z1,B) DFG789(ZI,B,delk),[0 5],[(0.1) 0 1]);
For your 3D plot, I would use the plot3 function.
You don’t report any problems in integrating your function otherwise, so I assume all is going well.
Pavan Kumar
Pavan Kumar 2015 年 1 月 29 日
編集済み: Pavan Kumar 2015 年 2 月 3 日
Made the recommended changes but still landing up in few errors.
Star Strider
Star Strider 2015 年 1 月 29 日
You need to be certain that the ‘dB(1)’ assignment returns only a single scalar value, not a vector. At least ‘R’ is a vector because ‘Ls’ is a vector (and so are all other variables that are functions of ‘Ls’). They cannot be, and still work in your ‘DFG789’ function. The output of your ‘DFG789’ function has to be a (3x1) column vector, ‘dB’.
Pavan Kumar
Pavan Kumar 2015 年 1 月 29 日
I am not knowing how t0 rectify the mistake, any suggestion on how to proceed with it?
Star Strider
Star Strider 2015 年 1 月 29 日
I am sorry, but I do not understand what you are doing. I can help with the MATLAB code if you have syntax or logic problems, but not in your writing your ‘DFG789’ function.
Pavan Kumar
Pavan Kumar 2015 年 1 月 29 日
I have got the right results using while delk=0 value with the same set of equations. But varying delk is causing the problem. i guess the equations are right,only the definition of delk is changed here.That's my confusion.
Star Strider
Star Strider 2015 年 1 月 29 日
Your ‘delk’ variable needs to be a scalar. That is why it works as zero. It is a vector because it is otherwise a function of ‘Ls’, and it cannot be a vector for it to work in your ‘DFG789’ function.
Pavan Kumar
Pavan Kumar 2015 年 1 月 29 日
Ok...In my case,it is definitely a vector so i need to alter something.Will slog it out..Thanks a lot bro..Will get back to you once i get the solution
Star Strider
Star Strider 2015 年 1 月 29 日
If ‘delk’ varies with ‘Z1’ or some other external variable, perhaps you can use that relationship to define it as a scalar for each iteration. Just a guess on my part.
Pavan Kumar
Pavan Kumar 2015 年 1 月 29 日
Is it possible to use ode45 for two variables like in this case B(1) is a function of delk and Z? If not,is there any other alternative?
Pavan Kumar
Pavan Kumar 2015 年 2 月 3 日
Hii Bro,
I got the solution to the problem,Thanks a lot for the advise.
Pavan
Star Strider
Star Strider 2015 年 2 月 3 日
My pleasure.
I would be interested in knowing how you solved the problem. I do not have sufficient understanding of the process you are modeling in your ODE to suggest a solution.
Pavan Kumar
Pavan Kumar 2015 年 2 月 9 日
編集済み: Star Strider 2015 年 2 月 9 日
Hii..Sorry for the belated reply.
I followed the following way
Delk=[1:20];
for i=1:20
delk=Delk(i)
[Z1,B] = ode45(@(t,x)DFG789(t,x,delk),[0 3],[(0.1) 0 1]);
Z1_complete(i,:,:)=Z1(:,:);
end
:)
Star Strider
Star Strider 2015 年 2 月 9 日
No worries!
Thank you for following up.
I was curious as to how you incorporated the vector into your ODE function, as much to satisfy my curiosity as to help anyone else who searches for your Question with the same problem.
Muhammad Muti ur rehman
Muhammad Muti ur rehman 2021 年 8 月 4 日
Hi strider I am usig bvp4c to solve coupled or non linear equation like velocity concentration temperature.. When i have to plot on velocity profile. I use the command plot (x1, y1(2, :)) for concentration 4 and temperature 6. If i have another linear equation like density of motile microorganism what number i should put.. To get the desired graph??

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

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by