Undefined function 'abs' for input arguments of type 'function_handle'
Mostrar comentarios más antiguos
Hi guys! I am getting this error when I try :
warning ('off','all');
beta1=0.2;
alphabar=-0.1;
theta4range=-1:0.1:4;
h4range=0:0.1:1;
c13range=-1:0.1:1;
% c23=-c13;
rmass=1.0;
rmomi= 2.0;
eps=0.01;
hassolution=0;
for theta4=theta4range
for h4=h4range
for c13=c13range
syms x;
H0=@(x) 1/2*(1-beta1.*x);
H14 =@(x)(-h4-theta4.*(x-1./2)+beta1);
H24 =@(x)(h4 + theta4.*(x-1./2));
u13=@(x)1./H0.* -4.* integral(H14,0,x) +c13;
u23=@(x)1./H0.* -4.* integral(H24,0,x) -c13;
p12 = @(x) -3.* integral(u13,0,x);
p22 = @(x) -3.* integral(u23,0,x);
kutta = @(x) 3.* integral(u23 - u13,0,1)+beta1.*alphabar;
lateral = @(x) integral(p22 - p12,0,1)-12.*rmass.*h4;
angular = @(x) integral((x-1./2).*(p22 - p12),0,1)-12.*rmomi.*theta4;
if abs(kutta)<eps & abs(lateral)<eps & abs(angular)<eps
c13
c23
theta4
h4
hassolution=1;
end
end
end
end
if ~hassolution
disp('No solution');
end
Respuestas (1)
John D'Errico
el 15 de Mzo. de 2015
Editada: John D'Errico
el 15 de Mzo. de 2015
0 votos
It is clearly time for you to learn about functions and how to call them. Start reading the basic tutorials.
Anyway, READ the error message. What is kutta? For that matter, what is lateral? And what is angular?
Answer: They are all function handles. They are NOT numbers. What is the absolute value of a number? That I can do. What is the absolute value of a function handle? Meaningless.
There is a difference between the function handle kutta as you have defined it, and the VALUE of that function on some input like kutta(x), where x is a variable.
By the way, why do you think you need to define the variable x as a symbolic one BEFORE you defined those function handles? There is no need to do so. That line of code was just a waste of CPU cycles.
What I don't know is if you actually want to do symbolic computation on those expressions, or if you want to do numerical computations. If your goal is symbolic computation, then all of those function handles were the wrong thing to do.
5 comentarios
dpb
el 15 de Mzo. de 2015
Yeah, but your colleague evaluated the functions, then used those results whereas your code uses the function handles as if they were those resulting results. Read the two pieces of code carefully in comparison to each other.
John D'Errico
el 15 de Mzo. de 2015
Editada: John D'Errico
el 15 de Mzo. de 2015
And do you understand the difference between his code and yours? (Even if we ignore the fact that he too has no comprehension of the lack of need for that syms line. It is just a waste of cpu cycles in his code too.)
See that the tests in HIS code are applied to variables, to NUMBERS.
What is firstexp, secondexp, thirdexp? They are all NUMBERS. NOT function handles. They are terrible examples of coding too, as naming your variables like that is a great way to write unreadable code.
I should point out that the code you got from your friend is a terribly poor piece of code to "solve" a nonlinear system of equations. I would suggest that your friend needs to learn about tools for solving nonlinear systems of equations. There are MANY of them available. You might start with fsolve.
Jan
el 15 de Mzo. de 2015
Warnings are extremely useful when running Matlab. Therefore warning ('off','all') is a very bad idea.
John D'Errico
el 15 de Mzo. de 2015
Jan makes a superb point. Warnings are there for a good reason. Disabling them is the equivalent to closing your eyes and your ears, and pretending that nothing is wrong. I see nothing. I hear nothing...
Categorías
Más información sobre Mathematics 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!