Matrix Error
3 views (last 30 days)
Show older comments
Greetings,
I am trying to model the system X(s)/E(s) = (-20.5s+41)/(s^2+7s+10). Where E(s) = U(s) - (X(s)^2-X(s)). U(s) is an impulse.
It is a negative feedback system in the s-domain.
The line e=... represents the calculation of the error of a feedback.
E
U --->+---->G(s)----->X(s)
^ |
| |
----(?)------
Where the output of (?) is represented by X(s)^2 - X(s).
So E(s) is the input of G(s) and X(s) is the output of G(s). It is a negative feedback system, so E(s) is represented by U(s)-( X(s)^2 - X(s)).
The block, (?), cannot be treated as X(s)-1.
Best way I could explain it...
I am getting an error
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in SysSimHW10p1 (line 45)
xdot1(2) = -7*x(2) - 10*x(1) + e;
that I am having trouble fixing.
% X(s) -20.5s + 41
%----- = --------------
% E(s) s^2 + 7s + 10
% E(s) = U(s) - [ (X(s)^2 - X(s) ]
clear all
close all
clc
N = 450;
T = .01;
X = [0 0];
x = zeros(1,N);
u = zeros(1,N);
xdot1 = x;
xdot2 = xdot1;
for n = 1:N-1
u(1) = .01;
e = u - x.*x + x;
xdot1(1) = x(2);
xdot1(2) = -7*x(2) - 10*x(1) + e;
x = x + (T/2)*(3*xdot1 - 1*xdot2);
xdot2 = xdot1;
X = [X (-20.5*x(2) + 41*x(1))];
end
t = T*[0:length(X)-1];
plot(t,X)
title('Impulse Response of System')
xlabel('Time')
ylabel('Amplitude')
Any help is appreciated!
0 Comments
Answers (1)
Geoff
on 20 Apr 2012
Well, u is a 1x450 vector, and x is a 1x3 vector. You can't add those together.
What is that line of code supposed to mean?
3 Comments
Geoff
on 20 Apr 2012
Okay, and what is 's'? I notice it's not in your code. Is that because you can use vector-operations to compute the entire X(s) without looping, or is that what you're doing with 'n'?
Everywhere else you use 'x', you're taking a scalar out of it (x(1), x(2)). Could it be that you're meant to do this for the line where your error occurs? Or should you be taking u(n) instead of u?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!