Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab program help

  1. Mar 14, 2007 #1

    kreil

    User Avatar
    Gold Member

    1. The problem statement, all variables and given/known data
    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?



    3. 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.
     
  2. jcsd
  3. Mar 14, 2007 #2
    you mean a matlab script right?
     
  4. Mar 14, 2007 #3
    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: Mar 14, 2007
  5. Mar 14, 2007 #4

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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
     
  6. Mar 14, 2007 #5

    kreil

    User Avatar
    Gold Member

    no, i dont know what the formulas are
     
  7. Mar 14, 2007 #6

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Then your first step must be looking up the definition of a derivative in your textbook.

    - Warren
     
  8. Mar 16, 2007 #7

    kreil

    User Avatar
    Gold Member

    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]
     
  9. Mar 16, 2007 #8
    Do you know how to program at all ?
    in any language?
     
  10. Mar 16, 2007 #9

    J77

    User Avatar

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Matlab program help
Loading...