Error in multolying a number and function handle
Show older comments
I appreciate if you suggest sth to solve this problem
clear
clc
ro=7800; %%%% density of workpiece in kg/m3
k=14; %%% thermal conductivity of workpiece W/mK
Cp=460; %%%% specific heat capacity of workpiece in J/Kg.k
K=9.2e-6; %%% thermal expansion coefficient in (1/k)
E=114e3; %%%% Young Modulus
nu=0.33; %%% Poisson ratio
eta=0.9; %%%% percentage of total shear energy converted to enthalpy
a=k/(ro*Cp); %% thermal diffusivity (m2/s)
kt=110; %%%%%%% thermal conductivity of workpiece W/mK
rot=15600; %%%% density of tool in kg/m3
Cpt=280; %%% specific heat capacity of tool in J/Kg.k
%%%%%%%%%%%%%
t1=1e-3; % cutting thickness in m
alfa=0; %% rake angle in deg
l=@(x) t1./sind(x(1)); %% leght of shear plane in m
V=1; %% cutting velocity in m/s
Vsh=@(x) V*cosd(alfa)./cosd(x(1)-alfa);
EpilonAB=@(x) (1/(2*sqrt(3)))*cosd(alfa)./(cosd(x(1)-alfa).*sind(x(1)));
EpilondotAB=@(x) (1/sqrt(3))*x(2)*Vsh(x)./l(x);
Rt= ro*Cp*V*t1/k;
tanfi=@(x) tand(x(1));
if Rt*tanfi(x) <10
bettaa=@(x) 0.5-(0.35*log10(Rt*tanfi(x)));
else
bettaa=@(x) 0.3-(0.15*log10(Rt*tanfi(x)));
end
I recive following error for the line including if
Unrecognized function or variable 'x'.
Error in tamrinfunction (line 40)
if Rt*tanfi(x) <10
5 Comments
John D'Errico
on 5 Feb 2025
What is your problem? What is the rest of your question?
However, when I am mutilpying a number to...
Stephen23
on 5 Feb 2025
"I recive following error for the line including if "
What do you expect the value of x to be on that line?
Reza
on 5 Feb 2025
Torsten
on 5 Feb 2025
Then define
bettaa=@(x) (0.5-(0.35*log10(Rt*tanfi(x)))).*(Rt*tanfi(x) <10) + (0.3-(0.15*log10(Rt*tanfi(x)))).*(Rt*tanfi(x) >=10);
If it's getting even more complicated, don't use function handles. Write a function with input x where you compute the results needed.
Reza
on 5 Feb 2025
Answers (1)
Walter Roberson
on 5 Feb 2025
tanfi=@(x) tand(x(1));
Up to this point, you are creating function handles -- pieces of code that do not take action directly, but can be passed parameters in order to execute.
if Rt*tanfi(x) <10
Here you are trying to invoke tanfi() on a parameter, x. That is a problem because x is not defined.
There are two possibilities here:
- That you actually have some specific parameter, x, that you are trying to evaluate those statements over; OR
- That you are trying to define conditional logic, creating a bettaa function handle that uses 0.5 or 0.3 depending on the results of Rt*tanfi(x) <10
If you are trying to create a conditional function handle, you need to do something like
bettaa = @(x) (Rt.*tanfi(x) < 10).*(0.5-(0.35*log10(Rt*tanfi(x)))) + (Rt.*tanfi(x) >= 10).*(0.3-(0.15*log10(Rt*tanfi(x))))
Categories
Find more on General Applications 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!