Originally Posted by

**ramdrop** My MATLAB knowledge is indeed poor because the lectures we have been given are just a sheet, the lecturer is never around to ask questions, usually these "sheets" are not really informative, they just work through examples, we're given them and then the lecturer wanders off for the majority of the class.

Im trying to learn MATLAB by myself because next year, I have a lot of MATLAB to do..

Okay, so this is EXACTLY what I want the m-file to do.

I want the m-file (for any function, x², exp(x)) defined as f, to be plotted on a graph, probably the best would be a 10 by 10. This is represented by:

Then, I want it to differentiate the function f, and plot that graph. Then it "approximates" the derivative for values of x = 0.01, 0.001, 0.0001. This causes the "curve/line" of the graph to change and become more accurate.

So in basic terms, the smaller the value of x, the more accurate the derivative plot is. This is represented by the latter part of the m-file.

Lets start at the begining:

[code]

function [ y ] = f( x )

% calculate f(x)=exp(x)

y=exp(x);

plot(x,f(x));

[\code]

1. I have told you before that you have a recursive call to f in this function definition that you almost certainly don't intend.

Create a file f.m which contains:

Code:

function [y]=f(x)
y=exp(x);

Now call this from the console with:

Code:

>>x=[-10:0.5:10]
>>y=f(x)
>>plot(x,y);

Now report what happens.

CB