×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

for loop

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
Replies continue below

Recommended for you

RE: for loop

(OP)
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

RE: for loop

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: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close