Vector multiplication in equation

12 visualizzazioni (ultimi 30 giorni)
Andrew Kay
Andrew Kay il 13 Dic 2018
Modificato: Stephen23 il 13 Dic 2018
I'm trying create values 'x' for the following equation but the values are not what i'm expecting
f=1:0.1:10
x=sqrt(a*b*c/d*e*f)
(With a,b,c being the numerator of the fraction and d,e,f being the denominator)
a,b,c,d,e are all constants in the equation with the only variable being f ranging from 1, 1.1, 1.2,...,...9.8,9.9,10
How would I code this? Thanks

Risposte (1)

Stephen23
Stephen23 il 13 Dic 2018
Modificato: Stephen23 il 13 Dic 2018
Use parentheses to group the denominator together, and use the correct division operator:
x=sqrt((a*b*c)./(d*e*f))
And tested:
>> a = 1;
>> b = 2;
>> c = 3;
>> d = 4;
>> e = 5;
>> f = 1:0.1:10
f =
1.00000 1.10000 1.20000 1.30000 1.40000 1.50000 1.60000 ...
>> x = sqrt((a*b*c)./(d*e*f))
x =
0.54772 0.52223 0.50000 0.48038 0.46291 0.44721 0.43301 ...
Read about the differences between matrix and array operations:
Using basic arithmetic will make no sense until you learn these differences!

Community Treasure Hunt

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

Start Hunting!

Translated by