Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

How to plot a functions in matlab

Asked by maharaj

maharaj (view profile)

on 23 Feb 2013

x ranges from 10-50 and y = [exp(-x)/x] - [exp(-(2+x))/(2+x)]

0 Comments

maharaj

maharaj (view profile)

Tags

Products

2 Answers

Answer by the cyclist

the cyclist (view profile)

on 23 Feb 2013
Accepted answer
x = 10:0.1:50;
y = (exp(-x)./x) - (exp(-(2+x))./(2+x));
plot(x,y)

0 Comments

the cyclist

the cyclist (view profile)

Answer by Youssef Khmou

Youssef Khmou (view profile)

on 23 Feb 2013
Edited by Youssef Khmou

Youssef Khmou (view profile)

on 23 Feb 2013

1. Using function handle :

 >>f=@(x) (exp(-x)./x)-(exp(-(2+x))./(2+x))
 >>x=10:0.1:50;
 >>plot(x,f(x))

2. Alternative using again Function Handle ;

 >>f=@(x) (exp(-x)./x)-(exp(-(2+x))./(2+x))
 >>fplot(f,[10 50])

3. Using M function in M file :

 % Save the function in M file 
 function y=R(x)
 y=(exp(-x)./x)-(exp(-(2+x))./(2+x));
 %------------------------------------ 
 % In the command prompt :
 >>x=[10:0.01:50];
 >>figure, plot(x,R(x))

4. Using Symbolic variables :

 >>syms x
 >>f=(exp(-x)./x)-(exp(-(2+x))./(2+x))
 >>ezplot(f,[10 50])

0 Comments

Youssef  Khmou

Youssef Khmou (view profile)

Contact us