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.
采纳的回答
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
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.
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
2015-1-29
编辑:Pavan Kumar
2015-2-3
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??
更多回答(1 个)
Taimur Zaman
2018-10-5
编辑:Walter Roberson
2021-10-6
1 个评论
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
