MATLAB: Setting up and plotting functions

equationfunctionMATLAB and Simulink Student Suiteplot

I'm quite new to matlab and I'm trying to grasp how to write functions and plot them as well.
One of my excercises in class asks me to:
"Make a function that plots the equation ax^2+bx+c=0, where a,b,c and x are used as input."
Does that mean I need to define values for a,b,c and x first, in order to plot anything?
Not sure how to best approach this in matlab.
My code so far looks like this:
function F(x,a,b,c);
y = a*x.^2+b*x+c;
plot(x,y)
end
But that doesn't plot anything as it is though..
I was hoping on some input on how to setup a good solution here, or maybe just a simple way by assigning values to the variables.. – Again, my coding skills are completely beginner, so any help is appreciated.

Best Answer

It's rough, but I'm also quite new to Matlab.
You answered your own question - you do need to define x, a, b and c.
x needs to be a vector (a series of values over which your function evaluates).
% xmin and xmax define the range over which your function plots
% xres defines how often a point is plotted (low number - smooth curve,
% high number, rough)
inputs = inputdlg({'x min','x max','x resolution','a','b','c'},'input)')
xmin = str2num(inputs{1})
xmax = str2num(inputs{2})
xres = str2num(inputs{3})
a = str2num(inputs{4})
b = str2num(inputs{5})
c = str2num(inputs{6})
x = xmin:xres:xmax
f(x,a,b,c)
function f(x,a,b,c)
y = a*x.^2+b*x+c;
plot(x,y)
end
Related Question