# 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일)
mohamerm belnbe 2023년 3월 20일
답변: Image Analyst 2023년 3월 21일
Vs+K*(C/(C-(u(1)*u(2)))*u(1))+R*u(1)-A*exp((-B/C)*u(1)*u(2))
##### 댓글 수: 2표시 이전 댓글 수: 1숨기기 이전 댓글 수: 1
mohamerm belnbe 2023년 3월 21일

댓글을 달려면 로그인하십시오.

### 답변(2개)

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 =
.
##### 댓글 수: 0표시 이전 댓글 수: -1숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

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.

댓글을 달려면 로그인하십시오.

### 범주

Find more on Data Type Identification in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by