Why Undefined operator '-' in function_handle?

When I enter ' H(3) ' in the command line, the following error is shown:
Undefined operator '-' for input arguments of type 'function_handle'.
Error in
Trial_H>@(m)d1+s*(cos(gama)+sum(cos(gama+(pi/2-phi_i))))+((2*r)-omega)*sin(B_j(m))+(r-omega)*sum(sin((1:m-1)*pi-sum(B_j(1:m-1))))
Here is the code:
% Variables
m = 3;
L = 10;
R = 1;
r = R/(m+1);
S = sqrt(2);
s = S/(m+1);
d1 = 1;
d2 = 0.25;
omega = R/(3*(m+1));
gama = atan(R/d1);
% Functions
phi_i = @(ii, m) atan( (d1+(ii*d2)./(m+1) )./(r/3) );
B_j = @(ii, m) 2*phi_i(ii, m);
H = @(m) d1 + s*( cos(gama) + sum(cos(gama+(pi/2-phi_i))) ) + ( (2*r)-omega)*sin(B_j(m) ) + (r-omega)*sum(sin((1:m-1)*pi - sum(B_j(1:m-1))));

8 comentarios

This statement uses variable m
r = R/(m+1);
But m is not defined in your code.
KSSV
KSSV el 7 de Abr. de 2020
Give the input to phi_i in H.
When I input:
phi_i(1,3)
The outputis the value of phi_i,
But I want to get the value for H
Jay
Jay el 7 de Abr. de 2020
Editada: Jay el 7 de Abr. de 2020
In that example, the source of the error is the use of an undefined variable.
So, you mean maybe I have undefined variable(s) or inputs.
Walter Roberson
Walter Roberson el 7 de Abr. de 2020
We mean that when you refer to phi_i inside H, phi_i is not going to be invoked as a function: it would not have any idea where to get its inputs from. The variables ii and m that are given as its parameters are local to it, as I described in the link above, and phi_i will not look in the calling environment to see if there happens to be variables named ii or m there. Parameters to a function handle are always strictly positional, so if you do not pass something to phi_i insid H then phi_i is not going to have any idea what values it should be run on.
If you want to invoke phi_i inside H, you need to pass it particular parameters.
Walter Roberson
Walter Roberson el 7 de Abr. de 2020
Editada: Walter Roberson el 7 de Abr. de 2020
H = @(m) d1 + s*( cos(gama) + sum(cos(gama+(pi/2-phi_i))) ) + ( (2*r)-omega)*sin(B_j(m) ) + (r-omega)*sum(sin((1:m-1)*pi - sum(B_j(1:m-1))));
^^^^^^
That is a reference to the anonymous function phi_i but it is not a call to run phi_i with particular parametrs.
B_j = @(ii, m) 2*phi_i(ii, m);
That defines B_j as being a handle to an anonymous function that expects two parameters
H = @(m) d1 + s*( cos(gama) + sum(cos(gama+(pi/2-phi_i))) ) + ( (2*r)-omega)*sin(B_j(m) ) + (r-omega)*sum(sin((1:m-1)*pi - sum(B_j(1:m-1))));
^^^^^^ ^^^^^^^^^^
Those two places, you try to invoke B_j with one parameter.
Where is the ii value coming from that you expect to pass into B_j and phi_i ?
Jay
Jay el 7 de Abr. de 2020
Editada: Jay el 7 de Abr. de 2020
I have to input a value for it. Thank you for the very explicit explanation

Iniciar sesión para comentar.

Respuestas (0)

Categorías

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

Productos

Versión

R2017b

Preguntada:

Jay
el 7 de Abr. de 2020

Editada:

el 7 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by