dividing defined variable by named variable
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
everytime i try to divide a defined variable by a calculated variable, it only outputs one number multiple times. What syntax am i missing?
d=1:.2:3;
a=sqrt((d.^2)*(3^2));
Y=d./a
1 Kommentar
Stephen23
am 28 Sep. 2022
Bearbeitet: Stephen23
am 28 Sep. 2022
" it only outputs one number multiple times."
Because that is the correct result for your code, which is equivalent to d./(3*d)
"What syntax am i missing?"
Because you did not state the expected output nor what you are trying to achieve, we cannot guess the syntax that is required to achieve an unstated goal.
Antworten (2)
Image Analyst
am 28 Sep. 2022
Well yeah. Just look at the numbers:
d = 1 : 0.2 : 3
a = sqrt((d.^2)*(3^2))
Y = d ./ a
They all look right to me. Exactly what output numbers did you expect? Tell me which element of Y it got wrong and should be a different number.
3 Kommentare
Image Analyst
am 28 Sep. 2022
You can define "a" differently then, like perhaps add noise
d = 1 : 0.2 : 3
a = sqrt((d.^2)*(3^2)) + rand(size(d))
Y = d ./ a
Walter Roberson
am 28 Sep. 2022
a=sqrt((d.^2)*(3^2))
3^2 is 9 so inside the sqrt() you have 9*d^2. sqrt() of that is sqrt(9)*sqrt(d^2). For positive d that is 3*d
Y = d ./ a
So you have d divided by 3*d. For non-zero d that is going to be 1/3 no matter what the positive value of d is. For negative d you would get -1/3. For 0 you get nan.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!