How to solve the differential equation say ode45 with multiple inputs(vector)
Mostra commenti meno recenti
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?
Risposta accettata
Più risposte (1)
Satyanarayan
il 16 Apr 2014
3 Commenti
Star Strider
il 16 Apr 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
il 16 Apr 2014
Star Strider
il 16 Apr 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!
Categorie
Scopri di più su Ordinary Differential Equations in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!