Can anyone help me with the error?

1 vue (au cours des 30 derniers jours)
Gaurav Srivastava
Gaurav Srivastava le 31 Mai 2019
Modifié(e) : Rik le 31 Mai 2019
edit by Rik (code originally posted as image):
clc
clear
disp(' Question Number 2')
x=0:1:10;
y=40./(1+((x-4).^2) + 5*sin((20*x)/pi));
fplot(y,x)

Réponse acceptée

Rik
Rik le 31 Mai 2019
Modifié(e) : Rik le 31 Mai 2019
You aren't plotting a function, but a vector. Replace fplot by plot, or replace your input by a function. Actually, doing both will teach you a valuable lesson about aliasing.
It is always a good idea to read the documentation carefully when you are getting unexpected results or errors.
Here is a code example of both options (using subplot to show them in one figure):
clc
%clear %no need to use clear
disp(' Question Number 2')
x=0:1:10;
f=@(x) 40./(1+((x-4).^2) + 5*sin((20*x)/pi));
y=f(x);
figure(1),clf(1)%only use clf in debugging
subplot(1,2,1)
plot(x,y)
ylim([-35 35])%ensure same view for both plots
subplot(1,2,2)
fplot(f,[min(x) max(x)])
ylim([-35 35])%ensure same view for both plots

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by