Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

for loop

Status
Not open for further replies.

wildany

Mechanical
Joined
Feb 6, 2015
Messages
2
Location
ID
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
 
Hi Greg,


Please neglect Y=C*Xdot0 and Xdot0=A*Xo+B*ft

the problem is only inside the 'for loop'.

Thanks a lot
Wildany
 
Well, there is certainly a problem in there, and I found the error message remarkably informative. It tells me which line the first error is on and what the problem is.

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
 
Could it possibly that you're setting x(i) to zero at each iteration?

Is this for school? Student postings are not allowed.

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529

Of course I can. I can do anything. I can do absolutely anything. I'm an expert!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top