当前位置:网站首页>MATLAB绘图函数fplot详解
MATLAB绘图函数fplot详解
2022-08-02 14:10:00 【杨老头软工】
MATLAB绘图函数fplot详解
一、fplot基本语法
fplot不同于plot,主要用来根据函数表达式和自变量所属区间来直接绘制函数曲线,不需要给出像plot需要给出的自变量和因变量的数组,因此当函数表达式已知的情况,使用fplot绘制函数曲线相对简单一些。
其基本语法如下:
1)fplot( f, xinterval, s )
其中f是函数中关于自变量的表达式,xinterval是自变量的取值范围,s表示图元的属性,和plot中的图元属性类似。当xinterval缺省的时候,自变量的默认区间是[-5, 5]。
2)fplot( fx, fy, tinterval, s )
此种形式主要用于绘制参数方程表示的函数曲线。其中fx和fy分别表示x和y关于参数t的表达式,tinterval是参数t的取值范围,s表示图元的属性。
3)fplot( @(var) f(var), xinterval, s )
其中@(var) 是声明var为自变量(可以根据需要给定该标识符),f(var)是具体的函数表达式,xinterval是自变量的取值范围,s表示图元的属性。
4)fplot( @(t)fx(t), @(t) fy(t), tinterval, s )
其中@(t) 是声明t为参数(可以根据需要给定该标识符),fx(t)和fy(t)是具体的参数方程横坐标和纵坐标的表达式,tinterval是参数t的取值范围,s表示图元的属性。
注意:用法1)和2)在新版本中会有告警提示。3)和4)是新版本中的标准用法。
二、具体的示例
例1.绘制y=sin(x)曲线图。
%示例代码(1)
clear all
clc
fplot( 'sin(x)' ) %只给定了函数表达式
%运行结果
%示例代码(2)
clear all
clc
fplot( 'sin(x)',[ -pi, pi ], 'ro' )
xlabel( 'x' );
ylabel( 'sin(x)' );
%运行结果
%示例代码(3)
clear all
clc
fplot( @(x)sin(x),[ -pi, pi ] )
xlabel( 'x' );
ylabel( 'sin(x)' );
%运行结果
例2.在同一个窗口绘制一个周期内的正弦曲线和余弦曲线
%示例代码
clear all
clc
fplot( @(x)sin(x),[ -pi, pi ], 'r-.' )
hold on
fplot( @(x)cos(x),[ -pi, pi ], 'b--' )
xlabel( 'x' );
ylabel( 'y' );
legend( 'y=sin(x)', 'y=cos(x)' );
%运行结果
例3.绘制单位圆
%示例代码
clear all
clc
fplot( @(t)sin(t), @(t)cos(t),[ -pi, pi ] ) %实线单位圆
hold on
fplot( @(t)sin(t), @(t)cos(t),[ -pi, pi ], 'ro' ) %单位圆的散点图
xlabel( 'x' );
ylabel( 'y' );
title( 'Unit Circle' );
axis equal
axis( [ -1.5, 1.5, -1.5, 1.5 ] );
%运行结果
例4.绘制分段函数曲线
%示例代码
clear all
clc
fplot( @(x)(7-x).^2/4,[1, 5 ], 'r' )
hold on
fplot( @(x)x-4,[5, 10 ], 'r' )
fplot( @(x)16-x,[10, 15 ], 'r' )
fplot( @(x)(x-13).^2/4,[15, 19 ], 'r' )
xlabel( 'x' );
ylabel( 'y' );
title( 'Piecewise Function Curve' );
axis( [ 0, 20, 0, 10 ] );
%运行结果
边栏推荐
猜你喜欢
Spark及相关生态组件安装配置——快速回忆
STM32LL库使用——SPI通信
Mapreduce环境详细搭建和案例实现
Win10系统设置application identity自动提示拒绝访问怎么办
为vscode配置clangd
What should I do if I install a solid-state drive in Win10 and still have obvious lags?
Mysql连接错误解决
基于深度学习的配准框架
General syntax and usage instructions of SQL (picture and text)
Impressions of Embrace Jetpack
随机推荐
Win11系统找不到dll文件怎么修复
Yolov5 official code reading - prior to transmission
pygame拖动条的实现方法
【我的电赛日记(完结)---2021全国大学生电子设计竞赛全国一等奖】A题:信号失真度测量装置
Open the door of power and electricity "Circuit" (2): Power Calculation and Judgment
mysql的索引结构为什么选用B+树?
DP4056电源保护芯片锂电池pin对pinTP4056
5. Use RecyclerView to elegantly achieve waterfall effect
Impressions of Embrace Jetpack
Win11怎么在右键菜单添加一键关机选项
GMP scheduling model of golang
The overlapping effect of the two surfaceviews is similar to the video and handout practice in the live effect
Spark及相关生态组件安装配置——快速回忆
2.4G无线小模块CI24R1超低成本
arm ldr系列指令
A clean start Windows 7?How to load only the basic service start Windows 7 system
arm push/pop/b/bl汇编指令
【STM32学习1】基础知识与概念明晰
Win7怎么干净启动?如何只加载基本服务启动Win7系统
FP7195大功率零压差全程无频闪调光DC-DC恒流芯片(兼容调光器:PWM调光,无极调光,0/1-10V调光)