Thread Subject: inserting a value in a function, but how?

Subject: inserting a value in a function, but how?

From: A

Date: 8 May, 2008 14:23:03

Message: 1 of 5

Hi

How can I insert a value to a function?

ie.

console
>>fun(log(x),2,0.01)

m-file
function out = fun(f,x,h)
% f should be ln(x), x should be 2 and h should be 0.01

v = f(x+h)-f(x)
% v should be ln(2+0.01)-ln(2), ans is 0.0049875

But it doesn't work.

Subject: inserting a value in a function, but how?

From: someone

Date: 8 May, 2008 15:04:04

Message: 2 of 5

"A " <amutka@welho.com> wrote in message <fvv2c7
$3mq$1@fred.mathworks.com>...
> Hi
>
> How can I insert a value to a function?
>
> ie.
>
> console
> >>fun(log(x),2,0.01)
>
> m-file
> function out = fun(f,x,h)
> % f should be ln(x), x should be 2 and h should be 0.01
>
> v = f(x+h)-f(x)
> % v should be ln(2+0.01)-ln(2), ans is 0.0049875
>
> But it doesn't work.

doc function_handle

% see the first example

Subject: inserting a value in a function, but how?

From: A

Date: 8 May, 2008 15:37:02

Message: 3 of 5

"someone " <someone@somewhere.net> wrote in message
<fvv4p4$58t$1@fred.mathworks.com>...
> "A " <amutka@welho.com> wrote in message <fvv2c7
> $3mq$1@fred.mathworks.com>...
> > Hi
> >
> > How can I insert a value to a function?
> >
> > ie.
> >
> > console
> > >>fun(log(x),2,0.01)
> >
> > m-file
> > function out = fun(f,x,h)
> > % f should be ln(x), x should be 2 and h should be 0.01
> >
> > v = f(x+h)-f(x)
> > % v should be ln(2+0.01)-ln(2), ans is 0.0049875
> >
> > But it doesn't work.
>
> doc function_handle
>
> % see the first example
>

I don't have matlab at home so I can't access the doc. Could
you post the example here?

Subject: inserting a value in a function, but how?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 8 May, 2008 16:16:31

Message: 4 of 5

In article <fvv6mu$qri$1@fred.mathworks.com>, A <amutka@welho.com> wrote:

>I don't have matlab at home so I can't access the doc. Could
>you post the example here?

google site:mathworks.com for the term you are looking for.


--
  "To burn always with this hard, gem-like flame, to maintain this
  ecstasy, is success in life." -- Walter Pater

Subject: inserting a value in a function, but how?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 8 May, 2008 16:20:32

Message: 5 of 5

In article <fvv2c7$3mq$1@fred.mathworks.com>, A <amutka@welho.com> wrote:

>How can I insert a value to a function?

>>>fun(log(x),2,0.01)

>m-file
>function out = fun(f,x,h)
>% f should be ln(x), x should be 2 and h should be 0.01

>v = f(x+h)-f(x)
>% v should be ln(2+0.01)-ln(2), ans is 0.0049875

That can only work if you have defined x as a sym. You have posted
several times before with basically the same problem and as best
I recall, none of those postings have had any indication that you
have the symbolic toolbox to work with.

But you don't need the symbolic toolbox if you modify very slightly:

>>>fun(@log, 2, 0.01)

And the m-file you show would stay exactly the same.
--
  "They called it golf because all the other four letter words
  were taken." -- Walter Hagen

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
function_handle someone 8 May, 2008 11:05:09
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com