MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by jasaswini mohanty
on 29 Apr 2013

i am designing the model of a bldc motor in which i need to solve some ode which are time varying. i don't know which matlab syntax will b helpful for me. kindly, suggest. my code is

X=[x1;x2;x3;x4;x5]; Xnew=A*X;

where A is a 5X5 matrix which is dynamic means varies with every iteration. and the initial conditions X(0) also varies with every iteration. how to solve these equations??

*No products are associated with this question.*

Answer by Jan Simon
on 29 Apr 2013

Accepted answer

It is not clear, what this means:

the initial conditions X(0) also varies with every iteration

Which iteration?

To solve the ODE use ODE45, if the problem is not stiff. The documentation `doc ode45` contains useful examples.

jasaswini mohanty
on 29 Apr 2013

ok thank u sir... here m posting my code.. t=1:0.001:2; Vmax=40; f=50;

increment=0.001; Va=Vmax*sin(2*pi*f*t); plot(t,Va,'r') hold on Vb=Vmax*sin(((2*pi*f*t)-(2*pi/3))); plot(t,Vb,'y') hold on

Vc=Vmax*sin(((2*pi*f*t)+(2*pi/3))); plot(t,Vc,'b') hold on

T=zeros(size(Va)); % for no load......

Xold=[0;0;0;0.2];

theta0=0.1; B=[117.65 0 0 0;0 117.65 0 0;0 0 117.65 0;0 0 0 11.24]; C=[1 0 0 0;0 1 0 0;0 0 1 0]; D=[0 0 0 0;0 0 0 0;0 0 0 0];

for i=1:1:5 U=[Va(i);Vb(i);Vc(i);T(i)];

if (theta0<0) theta0=360+theta0; disp('theta0=') disp(theta0)

end

%definition of fa................................ if (0<theta0&& theta0<=120) fa=1; elseif (120<theta0 && theta0<=180) fa=(6*(180-theta0)/180)-1; elseif (180< theta0 && theta0<=300) fa=-1; elseif (300<theta0 && theta0<=360) fa=(6*(theta0-360)/180)+1; end

f1(i)=fa;

%definition of fb................................ if (0<theta0 &&theta0<=60 || 300<=theta0 && theta0 <=360) fb=-1; elseif (60<theta0&&theta0<=120) fb=(6*(theta0-60)/180)-1; elseif (120<theta0 && theta0<=240) fb=1; elseif (240<theta0 && theta0<=300) fb=1-(6*(theta0-240)/180); end

f2(i)=fb;

%definition of fc.................................. if (0<theta0&&theta0<=60) fc=1-(theta0/30); elseif (60<theta0&&theta0<=180) fc=-1; elseif (180<theta0 && theta0<=240) fc=((theta0-180)/30)-1; elseif (240<theta0&& theta0<=360) fc=1; end

f3(i)=fc;

A=[-23.53 0 0 -17247.965*fa;0 -23.53 0 -17247.965*fb;0 0 -23.53 -17247.965*fc;1647.3*fa 1647.3*fb 1647.3*fc -0.0562]; disp('A=') disp(A)

end

now that i have A matrix and initial condition with me i want to find the solution for every states. and the initial condition varies in every time step. means at t=0 whatever is the value of the states that will b the initial condition for next time step. i hope this time my problem statement is clear.

## 0 Comments