There is something wrong in this script because when I run this program it shows file:line:1, coloum:1 invalid use of operator

15 vues (au cours des 30 derniers jours)
// to plot a graph of exponential function x=[0:.1:2]; //x y=exp(x); p1=1+x; p2=1+x+x^2; p3=1+x+x^2+x^3; p4=1+x+x^2+x^3+x^4;
plot(x,y,"ro-",x,pl,"rx-",x,p2,"gd-",x,p3,"ms-",x,p4,"k^-"); legend ("y","pl","p3","p3","p4");

Réponse acceptée

Voss
Voss le 6 Mar 2022
Modifié(e) : Voss le 6 Mar 2022
Use " % " to create a comment in MATLAB code.
Then use " .^ " rather than " ^ " when operating element-wise on an array (and use p1 instead of pl, etc.).
% to plot a graph of exponential function
x=[0:.1:2]; %x
y=exp(x); p1=1+x; p2=1+x+x.^2; p3=1+x+x.^2+x.^3; p4=1+x+x.^2+x.^3+x.^4;
plot(x,y,"ro-",x,p1,"rx-",x,p2,"gd-",x,p3,"ms-",x,p4,"k^-"); legend ("y","p1","p2","p3","p4");

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by