Matlab program help

  • MATLAB
  • Thread starter kreil
  • Start date
  • #1
kreil
Insights Author
Gold Member
668
67

Main Question or Discussion Point

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.
 

Answers and Replies

  • #2
236
0
you mean a matlab script right?
 
  • #3
236
0
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:
  • #4
chroot
Staff Emeritus
Science Advisor
Gold Member
10,226
34
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
 
  • #5
kreil
Insights Author
Gold Member
668
67
no, i dont know what the formulas are
 
  • #6
chroot
Staff Emeritus
Science Advisor
Gold Member
10,226
34
Then your first step must be looking up the definition of a derivative in your textbook.

- Warren
 
  • #7
kreil
Insights Author
Gold Member
668
67
i know what a derivative is, i dont know how to program in matlab.

[tex]f'(x)=\lim_{h{\rightarrow}0}\frac{f(x+h)-f(x)}{h}[/tex]
 
  • #8
236
0
Do you know how to program at all ?
in any language?
 
  • #9
J77
1,076
1

Related Threads on Matlab program help

  • Last Post
Replies
6
Views
21K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
2
Views
2K
  • Last Post
Replies
1
Views
749
Replies
3
Views
7K
  • Last Post
Replies
1
Views
3K
Replies
1
Views
4K
Top