matlab创建函数为什么要用 “点”符号?

23 views (last 30 days)
fa wu
fa wu on 20 Jun 2022
Answered: 埃博拉酱 on 23 Nov 2024 at 1:06
使用句柄调用函数的方式与直接调用函数一样。例如,假设您有一个名为 computeSquare 的函数,该函数定义为:
function y = computeSquare(x)
y = x.^2;
end
创建句柄并调用该函数以计算 4 的平方。
f = @computeSquare;
a = 4;
b = f(a)
复制代码
我发现创建的函数是 y = x.^2; 但是我将函数内容给改成y = x^2; 计算结果还是16,没有任何变化。所以这里为什么要有一个 “点”呢?
再看下边这个例子。
fun = @(x) exp(-x.^2).*log(x).^2;
计算 x=0 至 x=Inf 的积分。
q = integral(fun,0,Inf)
这个fun函数为什么 .*log 而不直接使用*log 呢? 在这个函数中我去掉点以后积分就会报错。
请问在此@x的作用是生命函数中哪一个字母才是变量,是么?
  1 Comment
Walter Roberson
Walter Roberson on 27 Nov 2022
In a comment elsewhere, you asked
关于函数间断点。在绘图的时候针对所有函数有什么办法让matlab“自动”在图上标注出间断点么?主要是可去间断点,不包括无穷间断点和震荡间断点。
which has an approximate translation of
"About function breakpoints. Is there any way for matlab to "automatically" mark discontinuities on the graph for all functions when plotting? Mainly it can go to the discontinuous point, excluding the infinite discontinuous point and the oscillation discontinuous point."
The answer is that fplot attempts to locate and mark discontinuities, but that when you call plot and similar functions you are passing only a list of points, and it is not possible for plotting routines to determine discontinuities from a list of points.

Sign in to comment.

Answers (1)

埃博拉酱
埃博拉酱 on 23 Nov 2024 at 1:06
点号并不是一个单独的符号,而是与.*构成一个与*完全不同的运算符,两者仅在作用于标量时等价。对于非标量运算两者完全不同。使用*等价于调用mtimes函数,而使用.*则等价于调用times函数

Categories

Find more on 文件操作 in Help Center and File Exchange

Tags

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!