Plotting a function with one parameter (MATLAB)

烂漫一生 提交于 2019-12-10 12:07:54

问题


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.


回答1:


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)



来源:https://stackoverflow.com/questions/21172326/plotting-a-function-with-one-parameter-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!