Calling function to evaluate another called function - delimeter error

I have two functions:
  1. One for the Lee-Kesler state equation (name: lk)
  2. One to find the root of an equation through the modified regular falsi method (name: wn). The inputs are (function to be evaluated, first root guess, second root guess, number of significant figures in final answer).
In a separate script, i am trying to call the mrf function to evaluate the lk equation as follows:
a=@wn(@lk,6,10,5)
However, when this is evaluated, I recieve the following error message:
Error: File: MainFunction.m Line: 51 Column: 18
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for
mismatched delimiters.
I am not sure what is causing this, nor how to remedy it.
Thank you

 Respuesta aceptada

a = wn(@lk,6,10,5)

6 comentarios

When I enter
a = wn(@lk,6,10,5)
I recieve another error:
Output argument "wn" (and maybe others) not assigned during call to "wn".
Error in MainFunction (line 53)
a=wn(@lk,6,10,5);
However, when i remove the "a = ", it works.
Is there any way i can fix this?
Your function wn must currently start
function wn = wn(something)
where you have an output variable name the same as the function name. You should avoid doing that: you can get into complications with accidentally making the function recursive. Use a different output variable name than the function name. And make sure you assign to the output variable.
Another possibility that we cannot rule out at the moment is that you have
function wn = some_other_name(something)
but you stored the code in wn.m . The first function in the file is known according to its file name, so it is not an error to have the first function in the file have a different name than the file. It is, however, confusing.
A third possibility that we cannot rule out at the moment is that have
function wn = some_other_name(something)
and that you took at (non-confusing at the time)
some_function_handle = @some_other_name
but that you then later did
wn = some_function_handle
This is legal but confusing.
In all three cases, your code is not assigning to the (first) variable named on the left side of the "=" of the function file.
"Is there any way i can fix this?"
Make sure that you define the output arguments within the function:
Avoid using the variable name wn if your function is called wn.
Thank you for your response.
I dont think it is a problem in the first suggestion:
function wn = wn(something)
end
%This is my function
function wn=mrf(f,a,b,n)
if f(a)*f(b)<=0
F=f(a);
G = f(b);
Wo = a;
while(1)
Wn = (G*a-F*b)/(G-F);
if f(a)*f(Wn) <= 0
b = Wn;
G = f(Wn);
if f(Wo)*f(Wn)>0
F = F/2;
end
else
a = Wn;
F = f(Wn);
if f(Wo)*f(Wn)>0
G = G/2;
end
end
if abs((Wn-Wo)/Wn)<(0.5*(10^(-n)))
% Wn
break
end
Wo=Wn;
end
format long
Wn;
%Displaying Appropriate Number of Sig. Figs.
Wn = round(Wn*10^n)/(10^n)
else
Wn = 'Wn = error, f(a)*f(b)>0';
disp(Wn)
end
end
I'm not sure if i am properly following your response, but i do not believe it could be the others either:
%Part 3 - Root via MRF
%Calling & Employing MRF fuction
u = wn(@lk,6,10,8);
I'm merely trying to, in this case, define u as the value wn(...) yields
function wn = wn(something)
end
That defines a function named wn but does not assign anything to the variable named wn
I suggest that you replace
function wn = wn(something)
end
%This is my function
function wn=mrf(f,a,b,n)
with
function Wn = wn(f,a,b,n)
@Walter RobersonAh that seems to have fixed the issue. Thank you very much for your help - I do appreciate it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Entering Commands en Centro de ayuda y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by