Invalid use of operator.

15 visualizaciones (últimos 30 días)
Daniel Araniz
Daniel Araniz el 27 de Oct. de 2020
Respondida: Steven Lord el 27 de Oct. de 2020
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.

Respuestas (2)

Walter Roberson
Walter Roberson el 27 de Oct. de 2020
The syntax for anonymous functions is @(list of variables) body
Instead you have @(expression) -Tsf

Steven Lord
Steven Lord el 27 de Oct. de 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.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by