Can anyone help me with the error?

1 visualización (últimos 30 días)
Gaurav Srivastava
Gaurav Srivastava el 31 de Mayo de 2019
Editada: Rik el 31 de Mayo de 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)

Respuesta aceptada

Rik
Rik el 31 de Mayo de 2019
Editada: Rik el 31 de Mayo de 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

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by