Borrar filtros
Borrar filtros

Hey! I am new to matlab and I need some help here.

2 visualizaciones (últimos 30 días)
Meghna
Meghna el 18 de Sept. de 2014
Comentada: Image Analyst el 18 de Sept. de 2014
So this is the problem: Write an equation that plots the quadratic formula, linearly spaced with 100 divisions. The equation for a particular quadratic expression should be in the form ax^2 +b^x + c,with the bounds on x are x1 and x2 where i t is assumed that x1 < x2. Using the functions linspace and plot may prove to be helpful as well as the hold switch. Make sure you include a title on the plot.
ANY HELP would be really appreciated!
  1 comentario
Image Analyst
Image Analyst el 18 de Sept. de 2014
Here's some help: http://www.mathworks.com/matlabcentral/answers/8626-how-do-i-get-help-on-homework-questions-on-matlab-answers. Basically you're supposed to at least do a little coding and ask specific, targeted questions, rather than just tell us the problem statement.

Iniciar sesión para comentar.

Respuesta aceptada

Mohammad Abouali
Mohammad Abouali el 18 de Sept. de 2014
Editada: Mohammad Abouali el 18 de Sept. de 2014
% Let's say:
a=3;
b=2;
c=1;
% we have y= ax^2 + bx + c;
% so the function to plot would be y=3x^2+2x+1;
p=[a, b, c];
% now let's say:
x1=-10;
x2=10;
n=100; %number of samples
x=linspace(x1,x2,n);
y=polyval(p,x);
plot(x,y)
title(sprintf('y= %fx^2 + %fx + %f',p(1),p(2),p(3)))
You can write that in function form as follows:
function myPlot(a,b,c,x1,x2,n)
p=[a, b, c];
x=linspace(x1,x2,n);
y=polyval(p,x);
plot(x,y)
title(sprintf('y= %fx^2 + %fx + %f',p))
end
Now you can call it as follow
myPlot(3,2,1,-10,10,100);

Más respuestas (1)

Naeem Roshan
Naeem Roshan el 18 de Sept. de 2014
Editada: Naeem Roshan el 18 de Sept. de 2014
introduce x and find y=ax^2+b^x+c (put numbers you want in place of x1,x2,step,a,b,c)
x = linespace(x1,x2,step);
y = a*x.^2 + b*x + c;
plot and its title
plot(x,y)
title('your title')
I hope this would be helpful :)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by