Unrecognized function or variable 'X0'.

when i run the command it says "Unrecognized function or variable 'X0'." I need help. Thank you
[X, FVAL]= FSOLVE(@mintafun,X0,options),

4 comentarios

Dyuman Joshi
Dyuman Joshi el 26 de Mayo de 2023
You need to define x0 and options outside of the ODE function.
And the function is fsolve in lower case. Also, there are multiple typos in your code (bracket misplaced, multiplication or division sign missing, etc) check out for them.
Bismark
Bismark el 26 de Mayo de 2023
i don't understand the first sentence please kindly clarify. x0 =[10, 4 6 , etc] in the code. I will go over the code to check the last statement. thank you.
Stephen23
Stephen23 el 26 de Mayo de 2023
"x0 =[10, 4 6 , etc] in the code"
x0 is not the same as X0
Bismark
Bismark el 26 de Mayo de 2023
i don't understand what that means

Iniciar sesión para comentar.

 Respuesta aceptada

Cris LaPierre
Cris LaPierre el 26 de Mayo de 2023
Editada: Cris LaPierre el 26 de Mayo de 2023
There are actually a lot of errors with your code. It might be worth taking a step back and thinking through your approach.
First, MATLAB is case-sensitive, which means FSOLVE and fsolve, X and x, etc are not equivalent statements.
Second, you have created a function that appears to be written upside down. It also appears to contain at the very bottom the inputs you are using to call the function in fsolve.
Third, you must be explicit in your use of mathematical operators to use. MATLAB does not assume anything. For example, sigma(X(14) should probably be sigma*(X(14)
Finally, check for typos. For example ((X13) should probably be (X(13)
As for the error you are seeing right now, it is likely because you are trying to call your function without defining the inputs. Here, for example, I haven't defined the variable X0 yet.
[X, FVAL]= FSOLVE(@mintafun,X0,options),
Unrecognized function or variable 'X0'.
The correct syntax might look like this, at which point, you will start getting new errors due to the other issues I describe above.
x0 = [10; 6; 4; 3; 4; 3; 2; 3; 18; 7; 25; 10; 5; 5; 4; 11; 8; 20; 6; 3; 8; 1; 30; 7; 2; 6; 14; 30;];
options=optimset('Display','iter');
[X, FVAL]= fsolve(@mintafun,x0,options),

4 comentarios

Here's a simple example adapted from the fsolve documentation page.
x0 = [0,0];
x = fsolve(@root2d,x0)
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
x = 1×2
0.3532 0.6061
function F = root2d(x)
y = 0.5;
F(1) = exp(-exp(-(x(1)+x(2)))) - x(2)*(1+x(1)^2);
F(2) = x(1)*cos(x(2)) + x(2)*sin(x(1)) - y;
end
Bismark
Bismark el 27 de Mayo de 2023
"Second, you have created a function that appears to be written upside down. It also appears to contain at the very bottom the inputs you are using to call the function in fsolve." kindly explain this for me.
Are you implying i start with X(1), X(2) ....etc. Should the equations be in ascending order of X?
Cris LaPierre
Cris LaPierre el 27 de Mayo de 2023
Editada: Cris LaPierre el 27 de Mayo de 2023
I refering to your defining equations that use variables that have not yet been defined. You can't use a variable (or array element, if that is your intent) if it hasn't yet been created.
Here's a shortened example
x0 = [10; 6; 4; 3; 4; 3; 2; 3; 18; 7; 25; 10; 5; 5; 4; 11; 8; 20; 6; 3; 8; 1; 30; 7; 2; 6; 14; 30];
F1 = mintafun(x0)
Unrecognized function or variable 'phi'.

Error in solution>mintafun (line 6)
F =X(5)/X(12) - phi*(1 - tau_c)*X(1) / theta*(1 - tau_w)*(1-X(4));
% The very first calculation uses phi, tau_c, theta, and tau_w, none of which exist yet.
function F = mintafun(X)
F =X(5)/X(12) - phi*(1 - tau_c)*X(1) / theta*(1 - tau_w)*(1-X(4));
tau_c = 0.17;
tau_w = 0.2;
theta = 0.349;
phi = 5;
end
Bismark
Bismark el 29 de Mayo de 2023
Perfect.Thank you

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2023a

Preguntada:

el 26 de Mayo de 2023

Comentada:

el 29 de Mayo de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by