what im doing wrong

1 次查看(过去 30 天)
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 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by