Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Undefined operand in function_handle

5 visualizaciones (últimos 30 días)
Jay
Jay el 7 de Abr. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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
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(1:m)))) ) + ( (2*r)-omega)*sin(B_j(m) ) + (r-omega)*sum(sin((1:m-1)*pi - sum(B_j(1:m-1))));

Respuestas (1)

Tommy
Tommy el 7 de Abr. de 2020
Where you call phi_i or B_j within the definition of H, you need to supply the arguments ii and m. For example,
..(pi/2-phi_i)..
is problematic because MATLAB thinks you are trying to subtract the function phi_i from pi/2. If you pass arguments,
..(pi/2-phi_i(1,m))..
for example, MATLAB will instead subtract the output of phi_i from pi/2.
  7 comentarios
Tommy
Tommy el 7 de Abr. de 2020
You cannot use m only, because your definition of B_j
B_j = @(ii, m) 2*phi_i(ii, m)
requires both ii and m.
Steven Lord
Steven Lord el 7 de Abr. de 2020
Calling B_j, which requires two inputs, with just one would be like me asking you "The first number is 7. What is the sum of the two numbers?" There's not enough information to answer the question.

La pregunta está cerrada.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by