for loop
for loop
(OP)
Dear All,
I want to create FOR LOOP by Matlab to solve this equation :
x(t+dt)=(dt*A+I)*x(t)+B*dt
in which
A =[0 1;-6 -5]
I=eye(2)
B=[0;1]
dt=0.01
initial condition
x(0)=[0;0]
x(t) = vector 2x1
Any one can give me some ideas ?
I have created some scripts in m file as per below :
ft=1; % Step Input
dt=0.01; % Time Interval (can be changed)
t_end=5; % End of Time for plotting (fix)
Nstep=round(t_end/dt);
Xo=zeros(2,1); % Initial Condition for X, at t=0
Xdot0=A*Xo+B*ft; % Intitial Condition for Xdot, at t=0
Y=C*Xdot0; % Intitial Condition for Y, at t=0
I=eye(size(A)); % Identity Matrix
for i=1:Nstep
x(i)= Xo
x(i+1)=(dt*A+I)*x(i)+B*dt;
end
However, It does not work
Thanks a lot
Wildany
I want to create FOR LOOP by Matlab to solve this equation :
x(t+dt)=(dt*A+I)*x(t)+B*dt
in which
A =[0 1;-6 -5]
I=eye(2)
B=[0;1]
dt=0.01
initial condition
x(0)=[0;0]
x(t) = vector 2x1
Any one can give me some ideas ?
I have created some scripts in m file as per below :
ft=1; % Step Input
dt=0.01; % Time Interval (can be changed)
t_end=5; % End of Time for plotting (fix)
Nstep=round(t_end/dt);
Xo=zeros(2,1); % Initial Condition for X, at t=0
Xdot0=A*Xo+B*ft; % Intitial Condition for Xdot, at t=0
Y=C*Xdot0; % Intitial Condition for Y, at t=0
I=eye(size(A)); % Identity Matrix
for i=1:Nstep
x(i)= Xo
x(i+1)=(dt*A+I)*x(i)+B*dt;
end
However, It does not work
Thanks a lot
Wildany
RE: for loop
Y=C*Xdot0; % Intitial Condition for Y, at t=0
accomplish?
Cheers
Greg Locock
New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?
RE: for loop
Please neglect Y=C*Xdot0 and Xdot0=A*Xo+B*ft
the problem is only inside the 'for loop'.
Thanks a lot
Wildany
RE: for loop
Personally I think you have got the algorithm completely wrong, but I don't play guessing games with bits of code.
Cheers
Greg Locock
New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?
RE: for loop
Is this for school? Student postings are not allowed.
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers
Of course I can. I can do anything. I can do absolutely anything. I'm an expert!