How to plot multiple graph

조회 수: 1 (최근 30일)
Nima Vali
Nima Vali 2020년 9월 21일
댓글: Nima Vali 2020년 9월 21일
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.
  댓글 수: 6
Nima Vali
Nima Vali 2020년 9월 21일
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
Nima Vali 2020년 9월 21일
but it comes with error

댓글을 달려면 로그인하십시오.

답변 (2개)

Jon
Jon 2020년 9월 21일
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);
Df= gradient(f)./gradient(x);
semilogx(x,f,'g')
hold on
semilogx(x,Df,'r')
grid
  댓글 수: 2
Jon
Jon 2020년 9월 21일
The key line is
Df= gradient(f)./gradient(x)
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
Nima Vali 2020년 9월 21일
Yes, I get it. Thank you for help.

댓글을 달려면 로그인하십시오.


Ameer Hamza
Ameer Hamza 2020년 9월 21일
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
  댓글 수: 3
Image Analyst
Image Analyst 2020년 9월 21일
And you might add a legend so you know what color is what.
legend('Original Signal', 'Derivative', 'Location', 'northeast');
Nima Vali
Nima Vali 2020년 9월 21일
yes, Thank you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by