简体   繁体   中英

Plotting a function with one parameter (MATLAB)

I would like to plot an function fx(y) = 3*yy.^(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 xa 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)

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM