# How to plot multiple graph

6 views (last 30 days)
Nima Vali on 21 Sep 2020
Commented: Nima Vali on 21 Sep 2020
Hello all
I am going to plot f= sin(5x)/x^3 and its derivative f '(x) within the domain x ∈[0.1,0.4]using semilogy plot.

Ameer Hamza on 21 Sep 2020
This seems like a homework question. What have you already tried?
Nima Vali on 21 Sep 2020
clc; clear all; close all;
syms x
x=logspace(0.1,0.4);
f(x)=sin(5*x)./(x.^3);
Df=diff(f,x);
semilogx(x,f(x),'g')
hold on
semilogx(x,Df,'r')
grid
Nima Vali on 21 Sep 2020
but it comes with error

Jon on 21 Sep 2020
I don't have the symbolic toolbox, but I could get your code to work by modifying as follows. Note I did not include the line syms x as I don't have the symbolic toolbox.
x=logspace(0.1,0.4);
f =sin(5*x)./(x.^3);
semilogx(x,f,'g')
hold on
semilogx(x,Df,'r')
grid

Jon on 21 Sep 2020
The key line is
This gives a simple numerical approximation to the derivative.
You can see what the gradient function does by typing doc gradient on the command line.
Nima Vali on 21 Sep 2020
Yes, I get it. Thank you for help.

Ameer Hamza on 21 Sep 2020
You are using the symbolic variables incorrectly. Check this code
% clc; clear all; close all;
syms x
f(x)=sin(5*x)./(x.^3);
Df = diff(f,x);
xv = logspace(0.1,0.4);
semilogx(xv, f(xv), 'g')
hold on
semilogx(xv, Df(xv), 'r')
grid Nima Vali on 21 Sep 2020
Yes Thank you for correction.
Image Analyst on 21 Sep 2020
And you might add a legend so you know what color is what.
legend('Original Signal', 'Derivative', 'Location', 'northeast');
Nima Vali on 21 Sep 2020
yes, Thank you.