How to plot a simple function that has a variable?
Mostrar comentarios más antiguos
The question I have is:
Write a MATLAB function
func(x,a) = x^2 + ax - 6
Use the function to plot, func(x,1), func(x,2) and func(x,3) on the same axes, for -10<x<10.
Im really confused how to define a as 1, 2 and 3 and how to substitute them into the function.
Respuesta aceptada
Más respuestas (2)
TADA
el 16 de Nov. de 2018
func = @(x,a) x^2 + a*x - 6;
x = -10:0.1:10;
for a = 1:3
plot(x, func(x,a ));
hold on;
end
Stephen23
el 16 de Nov. de 2018
0 votos
You can do this very simply by defining a normal function handle:
>> F = @(x,a) x.^2 + a*x - 6;
>> X = -10:.1:10;
>> plot(X,F(X,1),'r', X,F(X,2),'g', X,F(X,3),'b')

Categorías
Más información sobre Mathematics en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
