Clear Filters
Clear Filters

what im doing wrong

1 view (last 30 days)
Gentian Zavalani
Gentian Zavalani on 6 Jul 2013
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.

Accepted Answer

Walter Roberson
Walter Roberson on 6 Jul 2013
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 Comments
Walter Roberson
Walter Roberson on 6 Jul 2013
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 on 6 Jul 2013
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)

Sign in to comment.

More Answers (1)

Gentian Zavalani
Gentian Zavalani on 6 Jul 2013
Edited: Gentian Zavalani on 6 Jul 2013
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

Categories

Find more on Programming 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!