Reputation: 53
I am trying to enter an equation into MATLAB which contains about 5 variables. Here is what I did:
syms Pwf Pr Qo J Qmax
Pwf = Pr((1.266 - (1.25*Qo/Qmax))^2) - 0.125
I want to run it such that I can input different values for different variables per time, but it gives an error:
Invalid indexing or function definition.
How should I do it?
Thank you
Upvotes: 1
Views: 84
Reputation: 202
From what I understand you are trying to create a function called Pwf
which varies with respect to the values of Pr
, Qo
and Qmax
If that's the case, you can use syms
command in MATLAB to create a symbolic function Pwf with independent variables Pr
, Qo
and Qmax
syms Pwf(Pr, Qo, Qmax)
Pwf(Pr,Qo,Qmax) = Pr*((1.266 - (1.25*Q0./Qmax))^2) - 0.125;
This creates a symbolic function Pwf
and sumbolic variables Pr
, Qo
and Qmax
. You can then assign different values for the variables and call the function Pwf
Pr = 1;
Qo = 2;
Qmax = 10;
Pwf(Pr, Qo, Qmax)
This would yield you a result in fractions as follows.
ans = 113407/125000
You can get numeric output using double()
or vpa()
>> vpa(ans)
ans = 0.907256
>> double(ans)
ans = 0.9073
You have mentioned about another variable J
which is not used in the equation, which can be added in to the function in a similar way. You just have to call the function Pwf(Pr, Qo, Qmax)
each time you change the variable values.
Upvotes: 1