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.
0 个评论
采纳的回答
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
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!