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.

 Accepted Answer

Star Strider
Star Strider on 29 Jan 2015
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 Comments

Pavan Kumar
Pavan Kumar on 29 Jan 2015
Edited: Pavan Kumar on 3 Feb 2015
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.
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 on 29 Jan 2015
Edited: Pavan Kumar on 3 Feb 2015
Made the recommended changes but still landing up in few errors.
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’.
I am not knowing how t0 rectify the mistake, any suggestion on how to proceed with it?
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.
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.
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.
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
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.
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?
Hii Bro,
I got the solution to the problem,Thanks a lot for the advise.
Pavan
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.
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
:)
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.
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??

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!