Borrar filtros
Borrar filtros

Plot of a function

2 visualizaciones (últimos 30 días)
Saptarshi Bhattacharjee
Saptarshi Bhattacharjee el 2 de En. de 2012
I have a problem where I need to plot the curve of f(x) vs x.x=[0,4]. I am having problems as to dealing with the multiple outputs of f(x). Is there a way of accessing each element of x as in arrays and then compute the value of f(x) for that x and store it in another array? Finally i can plot the curve with help of values in x and f(x) vectors
  1 comentario
Walter Roberson
Walter Roberson el 2 de En. de 2012
Please do not use my email address as a Tag.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 2 de En. de 2012
numx = length(x);
fx = zeros(1, numx);
for K = 1:numx
fx(K) = f(x(K));
end
plot(x, fx);
However, keep in mind that
x = [0,4];
constructs x to have exactly two values, 0 and 4. There is no MATLAB construct to express a continuous range of values. You can use the colon notation to express lists of values, such as
x = 0 : 0.1 : 4;
or you can use linspace(), such as
x = linspace(0, 4, 51);
where the 51 is the total number of points including the two endpoints.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by