what im doing wrong

조회 수: 1 (최근 30일)
Gentian Zavalani
Gentian Zavalani 2013년 7월 6일
g=@(tu((i),j+1)) tu((i),j+1)-(1/2*(xu((i),j)-xu((i-1),j)+tu((i),j)+tu((i-1),j))+h/8*(r*(tu((i),j)-(1/f)*(tu((i),j))^3)+2*(r*(tu((i),j+1)-(1/f)*(tu((i),j+1))^3))+r*(tu((i-1),j)-(1/f)*(tu((i-1),j))^3)));
p=fzero(@(tu((i),j+1)) g,0);
but i got this answer
Unbalanced or unexpected parenthesis or bracket.

채택된 답변

Walter Roberson
Walter Roberson 2013년 7월 6일
When you construct an anonymous function, the part directly after the @ must be pure variable names and not expressions or indexed variables.
Something like
g = @(tu, i, j) tu((i),j+1)-(1/2*(xu((i),j)-xu((i-1),j)+tu((i),j)+tu((i-1),j))+h/8*(r*(tu((i),j)-(1/f)*(tu((i),j))^3)+2*(r*(tu((i),j+1)-(1/f)*(tu((i),j+1))^3))+r*(tu((i-1),j)-(1/f)*(tu((i-1),j))^3)));
p = fzero(@(i) g(tu, i, j), 0)
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 7월 6일
The syntax you are using in
fzero(@(tu((i),j+1)) g,0)
is wrong. What goes in the () after the @ can only be variable names. With what you used, MATLAB is confused when it sees the "g" after the ")" .
Walter Roberson
Walter Roberson 2013년 7월 6일
If you have an expression of the form
f(x) = g(x)
where g(x) is a function of x and includes the term f(x) somewhere inside, then rearrange the expression to
g(x) - f(x) = 0
and then you can solve for the x that makes it zero.
For example if
tu(i) = tu(i) * exp(-i^2) - cos(i)
then you can rearrange that to
tu(i) * exp(-i^2) - cos(i) - tu(i) = 0
and then you
fzero(@(i) tu(i) * exp(-i^2) - cos(i) - tu(i), InitialValue)

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

추가 답변 (1개)

Gentian Zavalani
Gentian Zavalani 2013년 7월 6일
편집: Gentian Zavalani 2013년 7월 6일
As you see this equation is implicit ,i wanna to solve this equation and to find tu((i),j+1) for each iteration so i don't know if you could suggest me any way,how to proceed to for example tu((i),j+1)=s i dont know something like that
pleas if you could give me a answer
regards

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by