和函数 fft2 和 ifft2 类似,函数 fftn 和 ifftn 对数据做多维快速傅立叶变换。 函数 fftshift 和 ifftshift 函数 fftshift 用于把傅立叶变换结果( 频域数据)中的直流分量( 频率为 0 处的值)移到中间位置。
其调用格式为: Y=fftshift(X)
e. Laplace变换
>> X=rand(3,3)
L=laplace(F) x s
X =
L=laplace(F,z) x z
0.9501 0.4860 0.4565
L=laplace(F,w,z) w z
0.2311 0.8913 0.0185 0.6068 0.7621 0.8214
>> Y=fft(X)
>> syms x s w z
Y =
1.7881 2.1394 >> laplace(sin(x))
1.2964
ans =
1/(s^2+1)
>> laplace(sin(x),w)
ans =
1/(w^2+1)
?x1?0.7sinx1?0.2cosx2?0 求方程组 ?? x 2 ? 0 . 7 cos x 1 ? 0 . 2 sin x 2 ? 0 的根。
首先编制函数文件fc.m
function y=fc(x)
y(1)=x(1)-0.7*sin(x(1))-0.2*sin(x(2));
y(2)=x(2)-0.7*cos(x(1))+0.2*sin(x(2));
y=[y(1),y(2)];
然后用fsolve求解
>>[x,fval,exitflag,output,jacob]=fsolve(‘fc’, [1.,1.],[])
%[1.,1.]为初值
x =
0.3367 0.5553
fval =
1.0e-008 *
0.2029 0.5242
exitflag = 1
解:
[x,y,z]=solve('x^2+sqrt(2)*x+2=0','x+3*z=4','y*z=-1','x','y','z')
x =
[ (-1/2+1/2*i*3^(1/2))*2^(1/2)]
[ (-1/2-1/2*i*3^(1/2))*2^(1/2)]
y=
[-51/73+3/73*i*3^(1/2)-27/146*(-1/2+1/2*i*3^(1/2))*2^(1/2)-3/146*2^(
1/2)]
[ -51/73-3/73*i*3^(1/2)-27/146*(-1/2-1/2*i*3^(1/2))*2^(1/2)-3/146*2^(
1/2)]
z =
[ -1/3*(-1/2+1/2*i*3^(1/2))*2^(1/2)+4/3]
[ -1/3*(-1/2-1/2*i*3^(1/2))*2^(1/2)+4/3] 求 f ,d g , f(0)=1, g(0)=2 的解。 d?f?g??f?g
dtdt
S = dsolve(’Df = f + g’,’Dg = -f + g’,’f(0) = 1’,’g(0) = 2’) S = f: [1x1 sym] g: [1x1 sym] S.f ans = exp(t)*(cos(t)+2*sin(t)) S.g
ans =
exp(t)*(-sin(t)+2*cos(t)) 函数 dsolve 命令求解微分方程时,如果得不到其解,则给出警告信息。
用命令plot(X,Y) 绘制图形。
x=1:length(peaks);
plot(x,peaks)
注意:
>> peaks
z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
- 1/3*exp(-(x+1).^2 - y.^2)
?x2?2x?2?0求非线性方程组? 的解 。
?x?3z?4 ?yz??1?
c.对数坐标曲线命令
绘制二维对数坐标曲线的命令semilogx、semilogy 和 loglog,其用法和函数 plot 相 同。
函数 semilogx 横坐标为对数坐标; 函数 semilogy 纵坐标为对数坐标; 函数loglog 横、纵坐标均为对数坐标。 绘制正弦函数的对数坐标曲线。 t=0.1:0.1:3*pi; y=sin(t); figure(1)
semilogx(t,y)
grid on %为图形窗口添加网格 figure(2) semilogy(t,y) figure(3)
loglog(t,y) 用 plotyy 函数绘制双 y 轴图形。 t1=0:0.1:3*pi; t2=0:0.1:6; y1=sin(t1); y2=sqrt(t2);
plotyy(t1,y1,t2,y2,'semilogx') grid on
用不同的线型和标注来绘制两条曲线。 t1=0:0.1:2*pi; t2=0:0.1:6; y1=sin(t1); y2=sqrt(t2);
plot(t1,y1,':hb',t2,y2,'--g')
用 subplot 函数把两种不同的图形综合在一个图形窗口中。
subplot(2,2,1)
t=0.1:0.1:2*pi;
y=sin(t);
semilogx(t,y)
grid on
subplot(2,2,2)
t=0:0.1:4*pi;
y=sin(t);
plot(t,y)
subplot(2,2,3)
x=1:0.01:5;
y=exp(x);
plotyy(x,y,x,y,’semilogx’,’plot’)
subplot(2,2,4)
x=1:0.1:10;
y=sqrt(x); plot(x,y,’:rd’)
用 mesh 命令绘制上例中的网格曲面。 [X,Y] = meshgrid(-2:.2:2, -2:.2:2); Z = X .* exp(-X.^2 - Y.^2); mesh(Z)
c. 三维表面命令 surf
函数 surf 可实现对网格曲面片进行着色,将网格曲面转化为实曲面。surf 命令的调用格式与 mesh 相同。
利用三维网格表面命令 surf 绘制图形。
z=peaks; %绘制山峰的图像,将函数值赋予变量z surf(z) %对山峰的图像进行着色处理