Undefined function 'abs' for input arguments of type 'function_handle'

7 次查看(过去 30 天)
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

回答(1 个)

John D'Errico
John D'Errico 2015-3-15
编辑:John D'Errico 2015-3-15
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 个评论
Jan
Jan 2015-3-15
Warnings are extremely useful when running Matlab. Therefore warning ('off','all') is a very bad idea.
John D'Errico
John D'Errico 2015-3-15
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...

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Nonlinear Dynamics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by