How to solve the differential equation say ode45 with multiple inputs(vector)
이전 댓글 표시
I have a a differential equation swing100
function dydt= swing100(t,y)
global Tm Te D H wB ;
dydt=[wB.*y(2);(0.5/H).*(Tm-Te-(D.*y(2)))];
This is called from a call_swing100.m file:
clc
clear all
global Tm Te D H wB ;
Tm=[1.0];
Te=[0.99];
D=[0];
H=[4];
wB=2*pi*50; %constant
y1=[0];
y2=[0];
y0=[y1; y2]; % intial conditions matrix
%dydt = odefun(t,y);
[t,y] = ode45(@swing100,[0 20],y0);
plot(t,y(:,1),'-',t,y(:,2),'--')
title('Solution of Swing Equation, ');
xlabel('time t');
ylabel('solution y');
legend('y_1','y_2')
This works Fine.
Now I want to solve the same with not one Tm but with say three values of Tm,Te,D,H. That is now Tm etc are vector inputs. So how do I do that? I have tried many 'wrong 'things and keep getting errors.
In simulink for example it works when I give an input vector. How do I do that in .m? Should I have to write a for loop and call each one once?
채택된 답변
추가 답변 (1개)
Satyanarayan
2014년 4월 16일
댓글 수: 3
Star Strider
2014년 4월 16일
I’m not sure I understand. In the code I wrote, you get all combinations of all variables in your vectors for both equations. Simply choose the combination you want from ymtx.
Satyanarayan
2014년 4월 16일
Star Strider
2014년 4월 16일
My pleasure!
You can use the array reference I used in the plot command to get the values you want from your ODE integrations.
And thanks!
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!