当前位置:网站首页>How to use matlab to implement the piecewise function "recommended collection"
How to use matlab to implement the piecewise function "recommended collection"
2022-08-03 14:15:00 【Full stack programmer webmaster】
Hello everyone, meet again, I'm your friend Quanstack Jun.
implement the following piecewise function: m = { t 0 ≤ t < 1 − t + 2 1 < t ≤ 2 0.1 else m=\left\{ \begin{array}{rcl} t & & {0 \leq t <1}\\ -t+2 & & {1 < t \leq 2}\\ 0.1 & & {other}\\ \end{array} \right.m=⎩⎨⎧t−t+20.10≤t<11 Explanation of the statement here: When (t>=0 & t<1) in the expression is established, the value of the Boolean expression at this time is True, and the value is 1, t*(t>=0 & t<1) = t1; the Boolean expressions (t>1 & t<=2) and (t<0 | t>2) in the expression do not hold at this time,Take 0 to participate in the operation, so at this time m=t1+(-t+2)0+0.10 = t; The drawing is as follows: Publisher: Full-stack programmer, please indicate the source: https://javaforall.cn/124797.htmlOriginal link: https://javaforall.cnMethod 1:
# Write a function script first; function m=fenduanhanshu(t)m=t.*(t>=0 & t<1)+(-t+2).*(t>1 & t<=2)+0.1.*(t<0 | t>2) # Note thisDot multiplication, otherwise an error will be reported that the dimensions of the internal matrix are inconsistent; end
# Call this function in the command window and draw a picture; >> x=0:0.01:2; >> m=fenduanhanshu(t); >> plot(m,t)
Method 2:
# Write a script and run it directly; t=-1:0.01:3; # Set according to your needs; m=zeros(size(t)); # Generate an all-zero matrix of the same size as matrix t; for i=1:length(t) # The length of the array (that is, in the number of rows or columns)larger value of ); if (t(i)>=0)&(t(i)<=1) m(i)=t(i); elseif (t(i)>1)&(t(i)<=2) m(i)=-t(i)+2; else m(i)=0.1; end end plot(t,m,'r') # 'r' means the line is red; grid on #Grid
>> t=-1:0.01:3; >> size(t) # When there is only one output parameter, return a row vector, the first element of the row vector is the number of rows of the matrix, and the second element is the number of columns of the matrix; ans = 1 401
B=zeros(n) # Generate n×n all-zero matrix; B=zeros(m,n) # Generate m×n all-zero matrix; B=zeros([m n]) # Generate m×n all-zero matrix; B=zeros(d1,d2,d3…) #Generate d1×d2×d3×...all zeros matrix or array; B=zeros([d1 d2 d3...]) # Generate d1×d2×d3×...all zeros matrix or array; B=zeros(size(A))# Generate an all-zero matrix of the same size as matrix A;
n=length(A) # If A is a non-empty array,Returns the larger value between the number of rows and the number of columns, which is equivalent to executing max(size(A)); # If A is an empty array, return 0; # If A is a vector, returnThe length of A; n=numel(A) # This statement returns the total number of elements in array A;
边栏推荐
- W11的右键如何改成和W10一样?(一行命令即可解决!)
- 系统学习Shell之正则表达式
- W11或W10系统如何进行休眠?
- MSF编码与upx加壳过杀软
- 位级运算之计算整数位级表示奇偶性
- Zhang Le: The Golden Triangle of R&D Efficiency and Practice in the Field of Demand and Agile Collaboration|Live Review
- Nanoprobes FluoroNanogold 偶联物的特色和应用
- 升级农企业务运营建设,智慧供应链管理平台打造“共赢生态链”
- Golang arrays and slices
- 可视化数据库设计软件有哪些_数据库可视化编程
猜你喜欢
随机推荐
Left index of all anagrams in leetcode/string (some permutation of s1 string is a substring of s2)
Relia Tech活性VEGFR重组蛋白丨小鼠 VEGF120实例展示
162_Power Query 快速合并文件夹中表格之自定义函数 TableXlsxCsv_2.0
GDB调试CoreDump文件
PyTorch framework to train linear regression model (CPU and GPU environment)
冰蝎加密 WebShell 过杀软
MySQL数据表操作实战
项目管理:PMP和IPMP哪个更值得考?两个证书的区别在于哪里?
驻冰岛使馆提醒旅冰中国公民务必加强安全防护
Golang sync.WaitGroup
Heaps
短视频的头号玩家:抖音产品体验报告
如何在 UE4 中制作一扇自动开启的大门
The maximum number of sliding window
游戏版号“地下交易”,一个版号能卖上千万?
投资75亿卢比!印度宣布建首座存储芯片组装和封测工厂,将于12月量产
Golang interface interface
varchar2和varchar2(char)_datetime数据类型
leetcode 448. Find All Numbers Disappeared in an Array 找到所有数组中消失的数字(简单)
[web penetration] detailed explanation of CSRF vulnerability