Clear Filters
Clear Filters

i have a syntax error in this expression : Vs+K*(C/(C​-(u(1)*u(2​)))*u(1))+​R*u(1)-A*e​xp((-B/C)*​u(1)*u(2))

11 views (last 30 days)
Vs+K*(C/(C-(u(1)*u(2)))*u(1))+R*u(1)-A*exp((-B/C)*u(1)*u(2))

Answers (2)

Star Strider
Star Strider on 20 Mar 2023
Checking it with the Symbolic Math Toolbox, it appears to be correct. The only suggestion I can offer is to use element-wise operations everywhere they appear to be appropriate, assuming that one or more of the values are arrays, and all the arrays are the same size —
Vs+K.*(C./(C-(u(1)*u(2)))*u(1))+R.*u(1)-A.*exp((-B./C)*u(1)*u(2))
Try that. Otherwise, without having access to the equation you are coding to see if you coded it correctly, we cannot determine what the problem is.
MATLAB interprets it as:
syms A B C K R u Vs
u = sym('u',[2 1])
u = 
Vs+K*(C/(C-(u(1)*u(2)))*u(1))+R*u(1)-A*exp((-B/C)*u(1)*u(2))
ans = 
.

Image Analyst
Image Analyst on 21 Mar 2023
Try breaking it up into smaller bite-sized terms, like
term1 = whatever
term2 = whatever
term3 = A * exp(term1)
etc.
Having long equations like you had often leads to mismatched parentheses and other errors.
Also, sometimes syntax errors report on one line when it was because the prior line was the one that actually had problems and included the next line as part of it. So be sure and check all nearby lines. You can even comment out the line it says and see if the syntax error goes away. It it did then the problem was on the line you commented out.

Community Treasure Hunt

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

Start Hunting!