From: MrMoo Rieks on 8 Jun 2010 09:43 Hello everybody, I have a question regarding anonymous functions. My problem is the following: "cp" is a function handle - a polynominal with "x" as variable now I want to define another function "s" which should be "cp/x". In Matlab: cp = @(x) (0.538657+9.11129*10^(-6)*x-90.2725*x.^(-1)-43449.3*x.^(-2)+1.59309*10^7*x.^(-3)-1.43688*10^9*x.^(-4))*50.2864; s = @(x) cp./x; So far no error: But once I try to integrate "s" I receivce an error: >> quad(s,298,1000) ??? Undefined function or method 'rdivide' for input arguments of type 'function_handle'. Error in ==> @(x)cp./x Error in ==> quad at 77 y = f(x, varargin{:}); Does anyone know a solution to this? Thanks a lot, Martin
From: David Young on 8 Jun 2010 09:49 "MrMoo Rieks" <mrmoo(a)abwesend.de> wrote in message <hulhd8$omc$1(a)fred.mathworks.com>... > ... > "cp" is a function handle - a polynominal with "x" as variable > now I want to define another function "s" which should be "cp/x". > ... > s = @(x) cp./x; I think this should be s = @(x) cp(x)./x;
From: Steven Lord on 8 Jun 2010 10:04 "MrMoo Rieks" <mrmoo(a)abwesend.de> wrote in message news:hulhd8$omc$1(a)fred.mathworks.com... > Hello everybody, > > I have a question regarding anonymous functions. My problem is the > following: > > "cp" is a function handle - a polynominal with "x" as variable > now I want to define another function "s" which should be "cp/x". > > In Matlab: > > cp = @(x) > (0.538657+9.11129*10^(-6)*x-90.2725*x.^(-1)-43449.3*x.^(-2)+1.59309*10^7*x.^(-3)-1.43688*10^9*x.^(-4))*50.2864; > > s = @(x) cp./x; This doesn't make sense. You can't divide a function handle by anything else, and MATLAB (correctly) errors when you try. What you CAN do is divide _the result returned by evaluating a function handle_ by something else -- that makes perfect sense. s = @(x) cp(x)./x; -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: MrMoo Rieks on 8 Jun 2010 10:17 "Steven Lord" <slord(a)mathworks.com> wrote in message <hulils$j0d$1(a)fred.mathworks.com>... > > "MrMoo Rieks" <mrmoo(a)abwesend.de> wrote in message > news:hulhd8$omc$1(a)fred.mathworks.com... > > Hello everybody, > > > > I have a question regarding anonymous functions. My problem is the > > following: > > > > "cp" is a function handle - a polynominal with "x" as variable > > now I want to define another function "s" which should be "cp/x". > > > > In Matlab: > > > > cp = @(x) > > (0.538657+9.11129*10^(-6)*x-90.2725*x.^(-1)-43449.3*x.^(-2)+1.59309*10^7*x.^(-3)-1.43688*10^9*x.^(-4))*50.2864; > > > > s = @(x) cp./x; > > This doesn't make sense. You can't divide a function handle by anything > else, and MATLAB (correctly) errors when you try. > > What you CAN do is divide _the result returned by evaluating a function > handle_ by something else -- that makes perfect sense. > > s = @(x) cp(x)./x; > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ > To contact Technical Support use the Contact Us link on > http://www.mathworks.com > Thanks David and Steve, this works perfectly!
|
Pages: 1 Prev: Remembering user input from an old execution Next: Error in betarnd toolbox function |