简体   繁体   English

使用一个参数绘制函数(MATLAB)

[英]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. 我想绘制函数fx(y)= 3 * yy。^(3)-x,其中x是参数。 I would like to graph fx(y) versus y for x varying over 0:0.5:6 all in one graph. 我想在一个图中将fx(y)与y相比较,x在0:0.5:6变化。 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. 出于某种原因,它仅在你给xa单值然后使用匿名函数时才有效,但这不是我需要的。

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

This gives me 3y-y^(3)-x = 0, but this is not what I need. 这给了我3y-y ^(3)-x = 0,但这不是我需要的。 I need to have a graph of fx versus y for the parameter x changing from 0 to 6 in steps of 0.5. 我需要有一个fx对y的图表,参数x从0到6逐步变为0.5。 This would give me length(x) number of graphs in one plot. 这将给出一个图中length(x)的图形数量。

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)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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