How to solve the differential equation say ode45 with multiple inputs(vector)
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (1)
Satyanarayan
le 16 Avr 2014
3 commentaires
Star Strider
le 16 Avr 2014
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
le 16 Avr 2014
Star Strider
le 16 Avr 2014
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!
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!