Undefined function 'abs' for input arguments of type 'function_handle'
6 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
John D'Errico
on 15 Mar 2015
Edited: John D'Errico
on 15 Mar 2015
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 Comments
Jan
on 15 Mar 2015
Warnings are extremely useful when running Matlab. Therefore warning ('off','all') is a very bad idea.
John D'Errico
on 15 Mar 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...
See Also
Categories
Find more on Nonlinear Dynamics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!