Borrar filtros
Borrar filtros

Undefined operator '*' for input arguments of type 'function_handle'.

2 visualizaciones (últimos 30 días)
i wrote a following code. every thing is right but it shows error" Undefined operator '*' for input arguments of type 'function_handle'.
clear all
clc
syms x
h=4;
q=100;
delta=26;
phi=39;
kh=0;
kv=0;
psi=atan(kh/(1-kv));
da1=delta*(pi/180); pha1=phi*(pi/180);
m=pha1+da1;
b=pha1-psi;
c=psi+da1;
gma=18.4; nq=2*q/(gma*(x));
delta=26;
phi=39;
lam=0;
A=lam*nq/(1+nq);
alphac=atan((sin(m)*sin(b)+(sin(m)^2+sin(b)^2+sin(m)*cos(m)*sin(b)*cos(b)+A*cos(c)*cos(m)*sin(b))^0.5)/(A*cos(c)+sin(m)*cos(b)));
w=0.5*gma*(x)^2*(1/tan(alphac));
B=(x)*((1/tan(alphac))-lam);
ka1=((1+nq)*(1-A*tan(alphac))*(cos(b)-(sin(b)/tan(alphac))))/(cos(psi)*(cos(m)+tan(alphac)*sin(m)))
wt=w+q*B;
pa1 = matlabFunction(0.5*gma*x^2*ka1);
x=0:0.1:5;
R=(wt*(1-kv)-pa1*sin(da1))/cos(alphac-pha1);
za1=(0.5*R*cos(pha1)*(x/sin(alphac))-q*B*(lam*x+0.5*B)-(1/6)*(1/tan(alphac))*(gma/tan(alphac))*x^3)/(pa1*cos(da1))
plot(za1(x),x)

Respuesta aceptada

Alex Mcaulley
Alex Mcaulley el 15 de Mzo. de 2019
Editada: Alex Mcaulley el 15 de Mzo. de 2019
You have some mix between symbolic functions and function handles. You need to choose one strategy. Try the following code, which uses only symbolic functions:
syms x
h=4;
q=100;
delta=26;
phi=39;
kh=0;
kv=0;
psi=atan(kh/(1-kv));
da1=delta*(pi/180); pha1=phi*(pi/180);
m=pha1+da1;
b=pha1-psi;
c=psi+da1;
gma=18.4; nq=2*q/(gma*(x));
delta=26;
phi=39;
lam=0;
A=lam*nq/(1+nq);
alphac=atan((sin(m)*sin(b)+(sin(m)^2+sin(b)^2+sin(m)*cos(m)*sin(b)*cos(b)+A*cos(c)*cos(m)*sin(b))^0.5)/(A*cos(c)+sin(m)*cos(b)));
w=0.5*gma*(x)^2*(1/tan(alphac));
B=(x)*((1/tan(alphac))-lam);
ka1=((1+nq)*(1-A*tan(alphac))*(cos(b)-(sin(b)/tan(alphac))))/(cos(psi)*(cos(m)+tan(alphac)*sin(m)))
wt=w+q*B;
pa1 = (0.5*gma*x^2*ka1); %changed
% x=0:0.1:5; %changed
R=(wt*(1-kv)-pa1*sin(da1))/cos(alphac-pha1);
za1=(0.5*R*cos(pha1)*(x/sin(alphac))-q*B*(lam*x+0.5*B)-(1/6)*(1/tan(alphac))*(gma/tan(alphac))*x^3)/(pa1*cos(da1))
fplot(za1,[0,5]) %changed
  1 comentario
Steven Lord
Steven Lord el 15 de Mzo. de 2019
Alternately if you want to use just function handles, you can't perform arithmetic with the function handles themselves but you can perform arithmetic on the values you receive when you evaluate the function handle.
f1 = @sin;
f2 = @cos;
x = 0:0.05:2*pi;
% Add the results of evaluating f1 and f2
willWork = @(x) f1(x)+f2(x);
figure
plot(x, willWork(x))
title('Will work')
% Try to add f1 and f2
willNotWork = @(x) f1+f2;
figure
plot(x, willNotWork(x)) % This line will error so ...
title('This line of code won''t be executed')

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by