0
$\begingroup$

I'm trying to plot this function

func=exp(x-sqrt(2))-cos(x-sqrt(2))-(x-sqrt(2)) 

in Matlab using 101 evenly spaced x values. If I just say

fplot(fun, [-1 3], 'o') 

the graph is the correct shape but the actual values of the points are determined by Matlab to give the best shape of the graph. I want to tell it exactly where to put the points, 101 evenly spaced between -1 and 3.

$\endgroup$
3
$\begingroup$

You can use linspace function,

x=linspace(-1,3,101);
func=exp(x-sqrt(2))-cos(x-sqrt(2))-(x-sqrt(2));
plot(x,func,'or');
$\endgroup$
  • $\begingroup$ Note that this also uses a different plot command: fplot wants as its first argument a string or a function handle, plot a vector. This will probably be confusing. $\endgroup$ – Federico Poloni Oct 25 '14 at 17:34
  • $\begingroup$ Thanks guys, this worked. I had tried doing this with fplot and it wasn't working correctly, so this is much better! $\endgroup$ – user11609 Oct 25 '14 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.