Formula result won't return a vector as exepected

10 Ansichten (letzte 30 Tage)
aviv kadair
aviv kadair am 7 Apr. 2018
Kommentiert: aviv kadair am 10 Apr. 2018
Hello,
In a simple home exercise we were given a formula which needs to be executed in two different scenarios.
1. In the first scenario, our L is a vector.
R = 22;
L = [100:20:300]
N=1;
X = (L*N)/(R+N)
X returns a vector with the correct numbers.
2. In the second scenario, I was meant to create N as a vector with the command N = [1:3:45].
R=22
L = 300
N = [1:3:45]
X = (L*N)/(R+N)
Now X only returns one single value, 161.9772, which I am not even sure where did it come from. So, please advise me what's wrong with my code.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 7 Apr. 2018
X = (L*N) ./ (R+N)

Weitere Antworten (1)

aviv kadair
aviv kadair am 7 Apr. 2018
LOL I actually figured it out the minute I sent this question. So, when do I use the colon sign before an operator? why didn't the first scenario required it?
Thanks
  2 Kommentare
Walter Roberson
Walter Roberson am 7 Apr. 2018
Your original code has a vector / a scalar. The operation of the / operator happens to be the same as the ./ operator when the denominator is a scalar.
Your second version of the code has a vector in the denominator. The / operator is different from the ./ operator when the denominator is not a scalar.
aviv kadair
aviv kadair am 10 Apr. 2018
Thank you for your answer, now I understand it clearly.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by