如何在 Octave 或 Matlab 中绘制具有两个变量的函数? [英] How can I plot a function with two variables in Octave or Matlab?

查看:42
本文介绍了如何在 Octave 或 Matlab 中绘制具有两个变量的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Octave 绘制具有两个变量的相当简单的函数,例如: f(x,y) = x^2 + 3y .绘制单变量函数很容易,但是我在找出如何绘制两个变量函数时遇到了很多麻烦.有谁知道这样做的最佳方法?

I want to use Octave to plot fairly simple functions with two variables like: f(x,y) = x^2 + 3y . It is very easy to plot single variable functions, but I am having a lot of trouble finding out how to do two variable functions. Does anyone know the best way of doing this?

推荐答案

绘制两个变量的函数通常意味着一个 3 维图 - 在 MATLAB 中,您可以为此使用函数 plot3.要在区间 [-10,10] 中为 X 和 Y 绘制函数 f(x,y),您可以使用以下命令:

Plotting a function of two variables would normally mean a 3-dimensional plot - in MATLAB you would use the function plot3 for that. To plot your function f(x,y) in the interval [-10,10] for both X and Y, you could use the following commands:

x = [-10:.1:10];
y = [-10:.1:10];
plot3(x, y, x.^2 + 3*y)
grid on

这篇关于如何在 Octave 或 Matlab 中绘制具有两个变量的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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