Solve f'(0) w/ MATLAB: Optimal h for f(x)=e^x

  • Context: MATLAB 
  • Thread starter Thread starter kreil
  • Start date Start date
  • Tags Tags
    Matlab Program
Click For Summary

Discussion Overview

The discussion revolves around writing a MATLAB program to compute the derivative of the function f(x) = e^x at x = 0 using different values of h (1, 0.1, 0.01, ..., 1E-9) with forward and central difference formulas. Participants are exploring how to implement this in MATLAB and what constitutes an optimal value for h.

Discussion Character

  • Homework-related, Technical explanation

Main Points Raised

  • One participant requests assistance in writing a MATLAB program, expressing a lack of programming knowledge.
  • Another participant suggests writing a function that takes h as input and outputs the derivative.
  • A participant emphasizes the importance of knowing the expressions for the derivative using forward and central difference formulas.
  • One participant indicates that the first step should be to look up the definition of a derivative in a textbook.
  • Another participant confirms understanding of the derivative concept but not how to program in MATLAB.
  • A participant provides a reference link related to finite difference methods, noting that programming skills are not a prerequisite for the question.

Areas of Agreement / Disagreement

There is no consensus on the optimal value of h or the specific programming approach, as participants are at different levels of understanding and knowledge regarding MATLAB and the mathematical concepts involved.

Contextual Notes

Participants express varying levels of familiarity with programming and mathematical concepts, which may affect their ability to engage with the problem effectively.

kreil
Science Advisor
Insights Author
Messages
665
Reaction score
68

Homework Statement


Write a MATLAB program to compute f'(0) for f(x)=e^x and h=1;0.1;0.01...1E-9 using the forward and central difference formula. What is the optimal h?



The Attempt at a Solution



I have no clue how to write programs in matlab, if anyone can help me get started I would REALLY appreciate it.
 
Physics news on Phys.org
you mean a MATLAB script right?
 
Anyway my advice is to write a function as have h as the input, and f' as the output..
in the function, you will just write the formula as a function of h.
as for which value is optimum, well it's related to how close it is to the real value...
 
Last edited:
Well, for staters, do you know the two expressions for the derivative that are mentioned in the assignment?

In other words, do you know how to express the derivative as each of these two kinds of differences?

- Warren
 
no, i don't know what the formulas are
 
Then your first step must be looking up the definition of a derivative in your textbook.

- Warren
 
i know what a derivative is, i don't know how to program in matlab.

[tex]f'(x)=\lim_{h{\rightarrow}0}\frac{f(x+h)-f(x)}{h}[/tex]
 
Do you know how to program at all ?
in any language?
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 4 ·
Replies
4
Views
9K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
9K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K