how to graph a polynomial in GUI using inputdlg or any other comand?

6 views (last 30 days)
the interfaz from GUI is going to ask a polinomial using inputdlg , that polinomial needs to be graph in a axes

Answers (1)

Star Strider
Star Strider on 16 Jul 2015
Here is one possibility:
coefc = inputdlg('Input the coefficients of your polynomial. For example, if it is x^2 + 2*x - 3, type 1, 2, -3 ');
coefd = str2num(coefc{:});
ordp = length(coefd)-1;
x = linspace(-5, 5, 50);
pv = polyval(coefd, x);
figure(1)
plot(x, pv)
grid
ttl = sprintf(['Polynomial with coefficients ' repmat('%.2f ', 1, length(coefd))], coefd);
title(ttl)
xlabel('x')
ylabel('y')
  2 Comments
Muthu Annamalai
Muthu Annamalai on 16 Jul 2015
Edited: Muthu Annamalai on 16 Jul 2015
Nice code; I checked that ezplot works too,
x = linspace(-5,5,50)
ezplot(@(x) polyval(coefd,x),linspace(-5,5,100))
Star Strider
Star Strider on 16 Jul 2015
Thank you.
Very good point. I thought about explot because it very conveniently writes the function above the plot, but decided to just use plot.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!