필터 지우기
필터 지우기

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))

조회 수: 6 (최근 30일)
Vs+K*(C/(C-(u(1)*u(2)))*u(1))+R*u(1)-A*exp((-B/C)*u(1)*u(2))

답변 (2개)

Star Strider
Star Strider 2023년 3월 20일
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 2023년 3월 21일
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.

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by