Hello, I am unsure if I am making a simple mistake but I am receiving errors for matrix size within my equation code. Here is the code:
for
Z = 0.1
W_n = 2.5;
B = sqrt(1 - Z^2);
Theta = atan(B/Z);
c(t) = 1 - (1/B) * exp(1) .^ -(Z * W_n * t) * sin(B * W_n * t + Theta);
end
I am receiving these error messages:
Error using * Inner matrix dimensions must agree.
Error in FeedbackControlSystem (line 65) c(t) = 1 - (1/B) * exp(1) .^ -(Z * W_n * t) * sin(B * W_n * t + Theta);
Error using ^ One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power.
Error in FeedbackControlSystem (line 65) c(t) = 1 - (1/B) * exp(1)^-(Z * W_n * t) * sin(B * W_n * t + Theta);
Any help would be greatly appreciated. Thank you!

7 commentaires

KSSV
KSSV le 18 Avr 2018
What is t here?
Veera Kanmani
Veera Kanmani le 18 Avr 2018
c(t) = 1 - (1/B) * exp(1) .^ -(Z * W_n * t) * sin(B * W_n * t + Theta);.. i think the problem occurs, can you specify code in detail manner and what is t value ?

This is the updated code: (Also I apologize for the response time)

for

t = linspace(1,3600,360000)

c = zeros(1,360000);

Z = 0.1;

W_n = 2.5;

B = sqrt(1 - Z^2);

Theta = atan(B/Z);

 c(t) = 1 - ((1/B) * (exp(1) .^ -(Z * W_n .* t)) * (sin(B * W_n .* t + Theta)));

end

I am trying to simulate a feedback control system and c(t) was a given equation.

These are the variables:

B = Beta % Beta value will change with each section

% B = sqrt(1 - Z^2)

% Z = Zeta % Zeta value will change with each section

% W_n = natural frequency % Natural frequency will change with each % section

% Theta = theta % Theta in radians

% Theta = atan(B/Z)

% tan(Theta) = B/Z

Jacob Hammer
Jacob Hammer le 24 Avr 2018
Updated Error Prompt:
>> FeedbackControlSystem Subscript indices must either be real positive integers or logicals.
Error in FeedbackControlSystem (line 67) c(t) = 1 - ((1/B) * (exp(1) .^ -(Z * W_n .* t)) * (sin(B * W_n .* t + Theta)));
Jacob Hammer
Jacob Hammer le 24 Avr 2018
Jacob Hammer
Jacob Hammer le 24 Avr 2018
Jacob Hammer
Jacob Hammer le 24 Avr 2018

Connectez-vous pour commenter.

 Réponse acceptée

Ameer Hamza
Ameer Hamza le 24 Avr 2018
From your code in the comment section, It can be seen that you are making a couple of mistakes.
  • t contain non-integers and thus can't be used to index c. In fact in this case you don't need to initialize c with zeros since it will not bring any speed up. Pre-allocation is only useful if your array size is changing in every loop iteration, here you can avoid that as given in below code snippet.
  • Not taking care of matrix dimension when multiplying. In MATLAB * is for matrix multiplication and .* is for element-wise multiplication. (exp(1) .^ -(Z * W_n .* t)) is 1*360000 and (sin(B * W_n .* t + Theta))) is also 1*360000. Therefore you need .* operation between them.
t = linspace(1,3600,360000);
Z = 0.1;
W_n = 2.5;
B = sqrt(1 - Z^2);
Theta = atan(B/Z);
c = 1 - ((1/B) * (exp(1) .^ -(Z * W_n .* t)) .* (sin(B * W_n .* t + Theta)));

4 commentaires

Jacob Hammer
Jacob Hammer le 24 Avr 2018
When using this specific code, c yields 1. Shouldn't c yield a matrix of the same dimensions as t?
Jacob Hammer
Jacob Hammer le 24 Avr 2018
Correction: When eliminating the for loop, c yields a matrix of the same dimensions as t, but consists of only 1's
Jacob Hammer
Jacob Hammer le 24 Avr 2018
Pardon the second correction but I just realized my time vector is much too large to see the actual fluctuations within the plot. Thank you for your help.
Ameer Hamza
Ameer Hamza le 24 Avr 2018

Yes, t and c have same dimensions. But the range of t is rather too large to see anything useful in plot. You might want to reduce the range of t.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by