Invalid use of operator.
7 views (last 30 days)
Show older comments
fun =@(Two-((Two-Tso)/(1+(Ks/Kw)))-((Ks/Kw)*((Two-Tso)/(1+(Ks/Kw))))*exp((-Ks-Kw)*tsf))-Tsf;
hA = fzero(fun,10)
With the above function, and all varibles accounted for, I am gettin getting the error below in regards to 1st minus sign. Why?
>> Project1b
Error: File: Project1b.m Line: 31 Column: 11
Invalid use of operator.
0 Comments
Answers (2)
Walter Roberson
on 27 Oct 2020
The syntax for anonymous functions is @(list of variables) body
Instead you have @(expression) -Tsf
0 Comments
Steven Lord
on 27 Oct 2020
Let's play "Count the parentheses". The way to play:
- Start a counter at 0.
- Whenever you see a ( add 1 to the counter.
- Whenever you see a ) subtract 1 from the counter.
If the counter ever goes negative, you have too few left parentheses or too many right parentheses or you have them in the wrong places.
If the counter does not go to 0 at the end of the line, you don't have enough right parentheses.
With Walter's suggestion about adding the right parenthesis for the input argument of the anonymous function, here's what I see when I play:
fun =@(Two) -((Two-Tso)/(1+(Ks/Kw)))-((Ks/Kw)*((Two-Tso)/(1+(Ks/Kw))))*exp((-Ks-Kw)*tsf))-Tsf;
0 1 0 12 1 2 3 210 12 1 23 2 3 4 3210 12 1 0X
X is where the counter would go to -1. Determine which is the correct ) to delete. I would consider defining a different variable, maybe R for ratio, and using it in place of the value Ks/Kw to eliminate a few sets of parentheses.
0 Comments
See Also
Categories
Find more on Logical 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!