Error in multolying a number and function handle

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 Kommentare

What is your problem? What is the rest of your question?
However, when I am mutilpying a number to...
"I recive following error for the line including if "
What do you expect the value of x to be on that line?
Reza
Reza am 5 Feb. 2025

It should be x(1) belonging to the matrix x=[x(1) x(2) x(3)] that will be defined later while optimizing by particleswarm

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
Reza am 5 Feb. 2025

Thank you. I’ll go forward to check if it works with function instead of function handle

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 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:
  1. That you actually have some specific parameter, x, that you are trying to evaluate those statements over; OR
  2. 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))))

Kategorien

Mehr zu General Applications finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 5 Feb. 2025

Kommentiert:

am 5 Feb. 2025

Community Treasure Hunt

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

Start Hunting!

Translated by