如何在MATLAB中使用ezplot? [英] How to use ezplot in MATLAB?

查看:393
本文介绍了如何在MATLAB中使用ezplot?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MATLAB中使用ezplot,并且由于我要绘制的函数包含大量术语,因此我可以将其拆分为较小的函数.让我举一个例子,说明少量术语,并且可以将其概括为大量术语.要绘制函数:

I want to use ezplot in MATLAB, and because the function I want to plot consists of a large number of terms I may split it into smaller functions. Let me give an example of a small number of terms and it can be generalized to a large number of terms. To plot the function:

y2+xy+xy3+x+1=0

我让y1=x+1并在MATLAB中编写以下代码:

I let y1=x+1 and I write the following in MATLAB:

x=[0:1:5]
y1=x+1
ezplot('y.^2+x*y+x*y.^3+y1')

但是有一个错误.请告诉我如何纠正错误.是否可以使用此功能(将方程式或函数分解为多个项)?

But there is an error. Please tell me how can I correct the error. Is it possible to use this feature (splitting the equation or function into a number of terms)?

推荐答案

您的错误是由于尝试将x+1替换为y1引起的. ezplot 要求符号表达式只能是2个符号变量的函数.但是,在调用ezplot时有 3 个符号变量(xyy1):

Your error is caused by trying to replace x+1 with y1. ezplot requires that symbolic expressions are functions of only 2 symbolic variables. However, there are 3 symbolic variables (x, y, and y1) in your call to ezplot:

ezplot('y^2+x*y+x*y^3+y1');

如果您使用原始方程式,那么一切都会正常运行

If you use your original equation, everything should work fine:

ezplot('y^2+x*y+x*y^3+x+1');

编辑:如果您感到好奇...

In case you were curious...

如果要绘制包含3个变量的方程式,则首先需要求解其中一个方程式,然后使用函数此答案中显示我回答了另一个SO问题).从技术上讲,y1是您定义它的依赖变量(因为它取决于变量x).但是,为了下面的示例,我们假定它是一个独立变量.等式:

If you want to plot an equation with 3 variables, you will first need to solve the equation for one of them and then use the function ezsurf (this is illustrated in this answer I gave to another SO question). Technically, y1 is a dependent variable the way you have defined it (since it depends on the variable x). However, for the sake of the following example, let's assume it's an independent variable. The equation:

y^2 + x*y + x*y^3 + y1 = 0

将解决y1以获得以下内容:

would be solved for y1 to get the following:

y1 = -y^2 - x*y - x*y^3

y1的绘制方式如下:

ezsurf('-y^2-x*y-x*y^3');

这篇关于如何在MATLAB中使用ezplot?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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