绘制具有一个参数的函数 (MATLAB) [英] Plotting a function with one parameter (MATLAB)

查看:37
本文介绍了绘制具有一个参数的函数 (MATLAB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个函数 fx(y) = 3*y-y.^(3)-x,其中 x 作为参数.我想在一张图中绘制 fx(y) 与 y 的关系图,其中 x 在 0:0.5:6 上变化.出于某种原因,它仅在您给 x 一个值然后使用匿名函数时才有效,但这不是我需要的.

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)

这给了我 3y-y^(3)-x = 0,但这不是我需要的.对于参数 x 从 0 到 6 以 0.5 的步长变化,我需要有一个 fx 与 y 的关系图.这会给我 length(x) 一个图中的图形数量.

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.

推荐答案

怎么样:

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)

这篇关于绘制具有一个参数的函数 (MATLAB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆