Doubt in the implementation of the Matlab function ode45

Asked

Viewed 536 times

-1

I never used the function ode45 of Matlab. Below the function and the program I developed, someone, please, can help me find the errors?

-Function

Function di=didt(t,i,flag,R,L,v,f,Rsec) I1=i(1); I2=i(2); A=L; D=L*R; w=2*pi*f;

di(1)=A(1,1)(vcos(w*t))+A(1,2)RsecI2+A(1,3)*((D(3,1)*I1+D(3,2)I2... -A(3,1)(vcos(wt))-A(3,2)RsecI2)/A(3,3))-D(1,1)*I1-D(1,2)I2; di(2)=A(2,1)(vcos(wt))+A(2,2)RsecI2+A(2,3)*((D(3,1)*I1+D(3,2)I2... -A(3,1)(vcos(wt))-A(3,2)Rseci2)/A(3,3))-D(2,1)*i1-D(2,2)*i2; di=[di(1) di(2)]';

end

-Program

% Definition of parameters R=[2.1581 0 0; 0 0.0114 0; 0 0 0.0556]; L=[8.7492 -8.7828 0.0336; -8.7828 12.3082 -3.5254; 0.0336 -3.5254 3.4918]; f=1e3; v=10e3; Rsec=100; I10=0; I20=0;

% Simulation time t=[0 10e-3];

[t,i]=ode45('didt',t,[i10 i20],[],R,L,v,f,Rsec) figure(1) Plot(t,i(:,1), t,i(:,2))

  • Please specify what you want to do with your program.

  • @Make sure to find I1 and I2 currents using Matlab’s ode45 function.

1 answer

0

There are several typing problems of your function definition and to be sure of the answer would need to show the original model you are trying to simulate. Trying to make a prior correction without this information, a program that works is as follows:

System definition:

function di=didt(t,i,R,L,v,f,Rsec) 

i1=i(1); i2=i(2); A=L; D=L*R; w=2*pi*f;

di(1,1)=A(1,1)*(v*cos(w*t))+A(1,2)*Rsec*i2+A(1,3)*((D(3,1)*i1+D(3,2)*i2... 
    -A(3,1)*(v*cos(w*t))-A(3,2)*Rsec*i2)/A(3,3))-D(1,1)*i1-D(1,2)*i2; 
di(2,1)=A(2,1)*(v*cos(w*t))+A(2,2)*Rsec*i2+A(2,3)*((D(3,1)*i1+D(3,2)*i2...
    -A(3,1)*(v*cos(w*t))-A(3,2)*Rsec*i2)/A(3,3))-D(2,1)*i1-D(2,2)*i2;

end

Program for the simulation:

% Definição dos parâmetros 
R=[2.1581 0 0; 0 0.0114 0; 0 0 0.0556]; 
L=[8.7492 -8.7828 0.0336; -8.7828 12.3082 -3.5254; 0.0336 -3.5254 3.4918];
f=1e3; v=10e3; Rsec=100; i10=0; i20=0;

% Tempo de simulação
ts=[0 10e-3];

[t,i]=ode45(@(t,y) didt(t,y,R,L,v,f,Rsec),ts ,[i10 i20])
figure(1) 
plot(t,i(:,1), t,i(:,2))

Note that there was the parameter flag not used and that to call the function ode45 with auxiliary parameters for the function it is necessary to define an anonymous function as it was done there @(t,y) didt(t,y,R,L,v,f,Rsec).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.