Вопрос

I would like to plot an function fx(y) = 3*y-y.^(3)-x with x being a parameter. I would like to graph fx(y) versus y for x varying over 0:0.5:6 all in one graph. For some reason it only works when you give x a single value and then use a anonymous function, but this is not what I need.

x=@(y) 3.*y-y.^(3)-x;
ezplot(fx)

This gives me 3y-y^(3)-x = 0, but this is not what I need. I need to have a graph of fx versus y for the parameter x changing from 0 to 6 in steps of 0.5. This would give me length(x) number of graphs in one plot.

Это было полезно?

Решение

How about:

y = -3:0.01:3;
x = 0:0.5:6;

n1 = numel(y);
n2 = numel(x);

fx = repmat(3.*y-y.^(3),n2,1)-repmat(x',1,n1);
plot(y,fx)

enter image description here

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top