当前位置:网站首页>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 ] );
%运行结果
边栏推荐
猜你喜欢
随机推荐
FP6293电池升压5V-12V大电流2APWM模式升压方案
arm push/pop/b/bl汇编指令
Win11 system cannot find dll file how to fix
Win7 encounters an error and cannot boot into the desktop normally, how to solve it?
【我的电赛日记(完结)---2021全国大学生电子设计竞赛全国一等奖】A题:信号失真度测量装置
Letter combination of LeetCode2 phone number
Detailed explanation of RecyclerView series article directory
win10任务栏不合并图标如何设置
推开机电的大门《电路》(二):功率计算与判断
In-depth understanding of Golang's Map
Please make sure you have the correct access rights and the repository exists.问题解决
GICv3/v4-软件概述
pygame拖动条的实现方法
What should I do if Windows 10 cannot connect to the printer?Solutions for not using the printer
Win10 Settings screen out from lack of sleep?Win10 set the method that never sleep
推开机电的大门《电路》(三):说说不一样的电阻与电导
发布模块到npm应该怎么操作?及错误问题解决方案
基于最小二乘法的线性回归分析方程中系数的估计
基于51单片机和物联网的智能家居系统(ESP8266物联网模块)
Mysql的锁








