Message Boards Message Boards

0
|
33086 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

How to evaluate a function at a point?

Posted 9 years ago
Clear["Global`*"]
eq[x] = f'[x] == 1/x
s[x] = DSolve[eq[x], f[x], x]
Print[Evaluate[s[1]]]
Evaluate[eq[1]]

How to evaluate a function at 1? The code does not produce a number.

POSTED BY: steve ma
3 Replies

Isn't this simply

In[4]:= DSolve[f'[x] == 1/x, f[x], x] /. x -> 1

Out[4]= {{f[1] -> C[1]}}
POSTED BY: S M Blinder

Is that not quite what I said, apart from my adding boundary conditions? I made up the boundary conditions so that Steve would get a number as he required.

Best wishes,

Marco

POSTED BY: Marco Thiel

Hi Steve,

there are a couple of things here. You might want to look at the examples given in the documentation for DSolve. The documentation is excellent and you would get your questions answered. Second, you might want to read:

http://community.wolfram.com/groups/-/m/t/270507

because it shows how to format code in your posts. It is much easier to answer your questions if you format the code appropriately.

Now, having said that, here is a piece of code that solves the ODE

    Clear["Global`*"] ;
    sol = DSolve[f'[x] == 1/x , f[x], x] ;
    f[x] /. sol
   (*{C[1] + Log[x]}*)

It would be easy to substitute a value for x now, but you still have the constant $C[1]$ because you have not provided initial conditions yet. This code fixes that:

Clear["Global`*"] ;
sol = DSolve[{f'[x] == 1/x , f[1] == 1}, f[x], x] ;
f[x] /. sol

Then you can simply use:

N[f[x] /. sol /. x -> 4]

to get a numerical solution at $x=4$.

Cheers,

Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract