Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

788 views
Skip to first unread message

Malgorzata Wieteska

unread,
May 31, 2016, 5:37:09 AM5/31/16
to
I get error message: Undefined operator '*' for input arguments of type 'function_handle'. while trying to use multiplication sign.
I try to solve system of differential equations. I have functions of time FSH(t) and LH(t) incorporated into equations and I don't know how to overcome that. I've tried also ode45 but it didn't work for me. My code is as follow:
>> b=0.004; %L/day
c1=0.0058; %(L/ug)/day
c2=0.048; %1/day
alpha=0.7736; %dimensionless
c2=0.048; %1/day
c3=0.004; %1/day
c4=0.061; %1/day
beta1=0.1566; %dimensionless
c5=1.2655; %1/day
gamma=0.0202; %dimensionless
d1=0.6715; %1/day
d2=0.7048; %1/day
k1=0.6876; %1/day
k2=0.69; %1/day
k3=0.6891; %1/day
k4=0.7093; %1/day

syms ReF(t)
syms SeF(t)
>> syms PrF(t)
>> syms Ov1(t)
syms Ov2(t)
>> syms Lut1(t)
>> syms Lut2(t)
>> syms Lut3(t)
>> syms Lut4(t)

FSH=@(t) 175*exp(-((t-5)^2)/110)+210*exp(-(t-15)^2)+65*exp(-((t-18)^2)/20)+174.85*exp(-((t-36)^2)/121)+205*exp(-(t-46)^2)+65*exp(-((t-49)^2)/20)+175*exp(-((t-67)^2)/130)
LH=@(t) 0.156+24.38*exp(-((t-7)^2)/230)+332.12*exp(-(t-15)^2)+17.24*exp(-((t-18)^2)/35.16)+24.38*exp(-((t-38)^2)/230)+332.12*exp(-(t-46)^2)+17.24*exp(-((t-49)^2)/35.16)+24.38*exp(-((t-69)^2)/230)

eqn1=diff(ReF)==b*FSH+(c1*FSH-c2*LH^alpha)*ReF;

Undefined operator '*' for input arguments of type 'function_handle'.
eqn2=diff(SeF)==c2*(LH^alpha)*ReF+[c3*(LH^beta1)-c4*LH]*SeF;
eqn3=diff(PrF)==c4*LH*SeF-c5*(LH^gamma)*PrF;
eqn4=diff(Ov1)==c5*(LH^gamma)*PrF-d1*Ov1;
eqn5=diff(Ov2)==d1*Ov1-d2*Ov2;
eqn6=diff(Lut1)==d2*Ov2-k1*Lut1;
eqn7=diff(Lut2)==k1*Lut1-k2*Lut2;
eqn8=diff(Lut3)==k2*Lut2-k3*Lut3;
eqn9=diff(Lut4)==k3*Lut3-k4*Lut4;

S=dsolve(eqn1,eqn2,eqn3,eqn4,eqn5,eqn6,eqn7,eqn8,eqn9)

ReFsol(t)=S.ReF
SeFsol(t)=S.SeF
PrFsol(t)=S.PrF
Ov1sol(t)=S.Ov1
Ov2sol(t)=S.Ov2
Lut1sol(t)=S.Lut1
Lut2sol(t)=S.Lut2
Lut3sol(t)=S.Lut3
Lut4sol(t)=S.Lut4

% initial conditions
ReF(0)==0

fplot(ReF)
hold on
fplot(SeF)
fplot(PrF)
fplot(Ov1)
fplot(Ov2)
fplot(Lut1)
fplot(Lut2)
fplot(Lut3)
fplot(Lut4)
grid on
legend('ReF','SeF','Location','best')

Steven Lord

unread,
May 31, 2016, 9:15:13 AM5/31/16
to


"Malgorzata Wieteska" <g.wie...@yahoo.ie> wrote in message
news:nijlvv$iov$1...@newscl01ah.mathworks.com...
> I get error message: Undefined operator '*' for input arguments of type
> 'function_handle'. while trying to use multiplication sign.

That's correct. You can't multiply a function handle. What you can do is
multiply _the result you get when you evaluate the function handle_.

f = @sin;
g = @cos;
h1 = f(5)*g(5) % WILL work
h2 = f*g; % WILL NOT work

If you need the result to be a function handle itself, use an anonymous
function.

h3 = @(x) f(x).*g(x)
h3(5) % WILL work

Note that inside h3 I evaluated f and g using h3's input. That is like
computing h1. Doing the following instead, which is like trying to compute
h2, would not work.

h4 = @(x) f.*g;
h4(5) % WILL NOT work


*snip*

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

0 new messages