Matlab绘制频散曲线程序代码(20210119130722)

Matlab绘制频散曲线程序代码(20210119130722)
Matlab绘制频散曲线程序代码(20210119130722)

Matlab绘制频散曲线

程序代码

-CAL-FENGHAI-(2020YEAR-YI

function disper

%绘制平板频散曲线

%tic

clc;clear;

cl=5790;%材料纵波波速(钢板)

cs=3200;%材料横波波速(钢板) dfd=*le3;

fdO=:dfd/le3:2O)*le3;%频厚积(MHz*mm) d_Q235二6;

cps_mi n二2700;

cpa_min=100;

cp_max=10000;

mode=3;%绘制的模式数

precision=le-8;

cpa=zeros(length(fdO),mode);

cps=zeros(le ng th(fdO),mode);

for i=l:length(fdO)

fd=fdO(i);

[cpl2 n]=ss(cps_min/cp_max/fd/cl,cs,mode);

for j=l:n

cpl=cpl2(j,l);

cp2=cpl2(j,2);

cps(i,j)=serfe n(cpl,cp2,fctcl£S'precisi on); end

[cpl2 n]=aa(cpa_min,cp_max/fd/cl/cs,mode); for j=l:n

cpl=cpl2(j,l);

cp2=cpl2(j,2);

cpa(ij)=aerfe n(cpbcp2,fd£l‘cs,precisi on); end

end

h=zeros(mode,2);

%相速度

figure(l)

for j=l:2

ifj==l

cp=cps;

color=,b,;

else

cp=cpa;

color二T;

end

for i=l:mode

cpp=cp(:,i);

in d=fi nd(cpp==0);

if ^isempty(ind)

h(i/j)=plot((fdO(ind(end)+l:end))/d_Q235/cpp(ind(end)+l:end),color);

else

h(i/j)=plot(fdO/d_Q235,cpp/color);

end

hold on

end

ifj==2

xlabel('f/(KHz)')

ylabel('C_{p}/(km-sA{-l})')

title('6mm钢板相速度频散曲线J

set(gca,,xtick,,(0::20)*le3/d_Q235,,xticklaber/(0::20)*le3/d_Q235)

xlim([0, 1000]);%

set(gca,'ylim,,[0 cp_max],'ytick,,(0:cp_max/le3)*le3,...

'yticklaber,0:cp_max/le3)

grid on

hSGroup = hggroup;%要在子对象构建之后构建,构建后立即使用,否则将失效

hAGroup = hggroup;

set(h(:/l)/parent,,hSGroup)

set(h(:,2)/parent,/hAGroup)

set(get(get(hSGroup,'A nn otationfLege ndlnformation'),..?

'Icon DisplayStyle'/on1);

set(get(get(hAGroup,'A nn otationfLege ndlnformatiorV),..?

'Icon DisplayStyle'/on1);

legend)'对称模式T反对称模式')

end

end

%群速度

figure(2)

for j=l:2

ifj==l

cp=cps;

color=,b,;

else

cp=cpa;

color=,r,;

end

for i=l:mode

cpp=cp(:,i);

in d=fi nd(cpp==0);

if ^isempty(ind)

fd=fdO(ind(end)+l:end)';

cpp=cpp(i nd(end)+l:end);

else

fd=fdO';

end

dcdf=diff(cpp)/dfd;

cg=cpp(l:end-l).A2./(cpp(l:end-l)-fd(l:end-l).*dcdf);

h(i,j)=plot(fd(l:end-l)/d_Q235,cg/color);

hold on

end

ifj==2

xlabel('f/(KHz)')

ylabel('C_{g}/(km-sA{-l})')

title('6mm钢板群速度频散曲线,)

set(gca,,xtick,,(0::20)*le3/d_Q235,,xticklaber/(0::20)*le3/d_Q235) xlim([0,1000]);%

set(gca;ylim,/[0]*le3;ytick,/(0::*le3,,yticklabel I,0::

grid on

hSGroup = hggroup;%要在子对象构建之后构建,构建后立即使用,否则将失效hAGroup

= hggroup;

set(h(:/l)/parent'/hSGroup)

set(h(:,2)/parent,,hAGroup)

set(get(get(hSGroup,'A nn otationfLege ndlnformatiorf),…

'Icon DisplayStyle'/on1);

set(get(get(hAGroup,'A nn otationJ/Lege ndlnformatiorV),..?

Ucon DisplayStyle'/on1);

legend)'对称模式,,反对称模式')

end

end

%toc

end

%对称模式

function [cpO n]=ss(cp_min/cp_max,fd,cl,cs/mode)

cp2=cp_mi n;

deter=33;

cp0=zeros(mode,2);

n=0;

while cp2

cpl=cp2;

cp2=cpl+deter;

yl=smode(cpl,fd/cl/cs);

y2=smode(cp2,fd/cl/cs);

while yl*y2>0&&cp2

cpl=cp2;

cp2=cpl+deter;

yl=smode(cpl/fd/cl,cs);

y2=smode(cp2/fd/cl,cs);

end

讦yl*y2<0

n=n+l;

cp0(n/:)=[cpl cp2];

else

if yl==0&&y2^=0

n=n+1;

A 7d <2*d )s 8*

d

d :7p 4±d )£f F d %H S 4

① s o 二 b

晏 d

y (尸 c b 、2

*

d

l

s 花

R V d r (尸d <

E *d )s o :J *7

d

<

p

r

_

d )

c

u

_

$7

d

%d 42 尿w 眠 b

?粢

俅I?d x p y d o oa oa s o c d

。奇S a

A 7c b 、2*d )-C s o ^(

d 晏 d

d

r u 30v (l ;R V ?-+

(

d

?d <2*

d )JZ s o :>*7c b 、p 4*d )

c

u

0F d %6s 4 尿MlHItb

足 d f s f v d

。七

三uv(p

、d£¥bs)sqe=:b

、((T R V (s

)s q f d (svqprcbopolusHSJ

u o l o u n j

pu

① P

U CD

P U CD

p u o

H+zdoHecb

,【

z d o z d o

H c c o d o "4-UHU

77d 0 T c b H r c

o d o WUHU

O

H H Z A oa od O H

A

4O S O

XH +e d f e d 。

CN

、(

rH d ¥e

d o N c b pue

P U CD

>l e

CN d o H H d

o

O H n ^>

4-

S

-(D

>l e

(D 」q

“d o H e d o OHHTA

CD S -CD

>l e

(D

q

0n H 0>

4O S 6

o d o H T d

end

%反对称模式

function [cpO n]=aa(cp_min,cp_max/fd z cl,cs,mode)

cp2二cp_mi n;

deter=33;

cp0=zeros(mode,2);

n=0;

while cp2

cpl=cp2;

cp2=cpl+deter;

yl=amode(cpl/fd,cl/cs);

y2=amode(cp2/fd,cl/cs);

while yl*y2>0&&cp2

cpl=cp2;

cp2=cpl+deter;

yl=amode(cpl/fd,cl/cs);

y2=amode(cp2/fd/cl/cs);

end

讦yl*y2<0

n 二n+1;

cpO(n/:)=[cpl cp2];

else

if yl==O&&y2^=O

n=n+1;

cpO(n,:)=[cpl cpl];

elseif y2==O&&yl~=O

n=n+1;

cp0(n/)=[cp2 cp2];

cp2=cp2+l;

elseif yl==O&&y2==O

n=n+l;

cpO(n,:)=[cpl cpl];

n=n+1;

cp0(n,:)=[cp2 cp2];

cp2=cp2+l;

end

end

end

end

function fs二amode(cp,fd£l,cs)

p=abs(sqrt((cp/cs)A2-l));

q=abs(sqrt((cp/cl)A2-l));

if cp<=cs%p和q都是复数

fs=-4*p*q*sinh(pi*fd/cp*p)*cosh(pi*fd/cp*q)+(-p A2-l)A2*sinh(pi*fd/cp*q)*cosh(pi*fd/cp*p); elseif cp>cs&&cp<=cl%p 是实数,q 是复数

fs=4*p*q*sin(pi*fd/cp*p)*cosh(pi*fd/cp*q)+(p A2-l)A2*sinh(pi*fd/cp*q)*cos(pi*fd/cp*p);

matlab相关图形实现代码

根据数据点绘制饼图和针状图: x=[1 2 3 4 5 6]; >> subplot(2,2,1);pie(x); >> subplot(2,2,2);pie3(x); >> subplot(2,2,3);stem(x); >>subplot(2,2,4);stem3(x); 5% 10% 14% 19% 24% 29% 24% 29% 19% 5%14% 10%0 2 4 6 2 4 6 5 10 01 2 05 10

根据数据点绘制向量场图、羽状图和罗盘图: x=[1 2 3 4 5 6];y=[1 2 3 4 5 6]; u=[1 2 3 4 5 6];v=[1 2 3 4 5 6]; subplot(2,2,1);quiver(x,y,u,v); subplot(2,2,2);quiver(x,y,u,v,'r'); subplot(2,2,3);feather(u,v); subplot(2,2,4);compass(u,v); 024680 246 802468 246 80 5 10 15 2 4 6 5 10 30 210 60240 90270 120 300 150330 180

rand(m,n)产生m ×n 均匀分布的随机矩阵,元素取值在0.0~1.0。 randn 函数:产生标准正态分布的随机数或矩阵的函数。 Y = randn(m,n) 或 Y = randn([m n])返回一个m*n 的随机项矩阵。 > theta=10*rand(1,50); %确定50个随机数theta >> Z=peaks; %确定Z 为峰值函数peaks >> x=0:0.01:2*pi;y=sin(x); %确定正弦函数数据点x.y >> t=randn(1000,1); %确定1000个随机数t >> subplot(2,2,1);rose(theta); %关于(theta )的玫瑰花图 >> subplot(2,2,2);area(x,y); %关于(x,y)的面积图 >> subplot(2,2,3);contour(Z); %关于Z 的等值线图(未填充) >> subplot(2,2,4);hist(t); %关于t 的柱状图 5 10 30 210 60 240 90270 120300150330 18000246 -1 -0.500.5 110 20 30 40 10 2030 40-4 -2 2 4 100 200 300

MATLAB程序代码

MATLAB 程序代码以及运行结果function [ ]= xy_1( A ) % Detailed explanation goes here x0=653.779 y0=604.47 %%%JD0的坐标 x1=757.119 y1=569.527 %%%JD1的坐标 dx=x0-x1 dy=y0-y1 L=(dx^2+dy^2)^0.5 %JD1到ID2的距离 T=T1(12,28,37) %%%切线长 xk0=T-L yk0=0 %JD2的局部坐标 c=0.9473 s=-0.3203 %%%预设cos和sin的值 %求左端缓和曲线坐标 for l=0:10:40 x=l-(l^5)/(40*(A^2))+l^9/(3456*(A^4)) %求左端缓和曲线X局部坐标 y=l^3/(6*A)-(l^7)/(336*(A^3)) %求左端缓和曲线Y局部坐标 dxk=x-xk0 dyk=y-yk0 B=[x0;y0]+[c,-s;s,c]*[dxk;dyk] %进行坐标换算 end end function [ T1 ] = T1( a,b,c) %求左端切线长 % Detailed explanation goes here A=a+b/60+c/3600 r=750 p1=p(40,750) p2=p(30,750) m1=m(40,750) T1=(r+p2-(r+p1)*cosd(A))/sind(A)+m1 end

function x = JZ1( ) %左端坐标系坐标转换矩阵 % Detailed explanation goes here x0=653.779 y0=604.47 %%%JD0的坐标 x1=757.119 y1=569.527 %%%JD1的坐标 dx=x0-x1 dy=y0-y1 L=(dx^2+dy^2)^0.5 %JD1到ID2的距离T=T1(12,28,37) %%%切线长 xk0=T-L yk0=0 %JD0的局部坐标 xk1=T yk1=0 %JD1的局部坐标 dxk=xk0-xk1 dyk=yk0-yk1 A=[dxk,-dyk;dyk,dxk] b=[dx,dy]' x=inv(A)*b %依次输出cos、sin 的值 end xy_1(30000) A = 30000 x0 = 653.7790 y0 = 604.4700 x1 =

Matlab程序代码

Matlab程序代码: clc; clear; N=20; T=0.1 t=0:T:N m=length(t) syms x1 x2 x3 fx=[0;x1+x2^2;x1-x2] gx=[exp(x2);exp(x2);0] hx=x3; R=10*eye(1) Q=[10 0 0;0 1 0;0 0 1] A=[0 1 0;0 0 1;0 0 0] B=[0;0;1] SS=B*inv(R)*B' [p1,p2,lamp,perr,wellposed,P]=aresolv(A,Q,SS) z1=hx z2=[diff(hx,x1) diff(hx,x2) diff(hx,x3)]*fx z3=[diff(z2,x1), diff(z2,x2), diff(z2,x3)]*fx ax=[diff(z3,x1), diff(z3,x2), diff(z3,x3)]*fx bx=[diff(z3,x1), diff(z3,x2), diff(z3,x3)]*gx z=[z1;z2;z3] k=inv(R)*B'*P %diff(z)=A*z+B*v=(A-B*K)*Z %x(0)=[1;0;0] abk=A-B*k x1(1)=1 x2(1)=0 x3(1)=1 z1(1)=x3(1) z2(1)=x1(1)-x2(1) z3(1)=-(x1+x2^2) for i=2:m z1(i)=z1(i-1)+T*(abk(1,1)*z1(i-1)+abk(1,2)*z2(i-1)+abk(1,3)*z3(i-1)) z2(i)=z2(i-1)+T*(abk(2,1)*z1(i-1)+abk(2,2)*z2(i-1)+abk(2,3)*z3(i-1)) z3(i)=z3(i-1)+T*(abk(3,1)*z1(i-1)+abk(3,2)*z2(i-1)+abk(3,3)*z3(i-1))

基于matlab的计算器编程附代码

1.需求分析 本次的实验要求是设计一个计算器,主要功能如下: (1)实现基本数学运算(加减乘除等),而且要能进行混合运算 (2)实现部分函数功能,如求平方根、求倒数等 (3)能实现小数运算 界面与标准计算器界面类似 根据要求以及以前的学习情况,决定使用matlab进行编程。Matlab强大的计算功能以及便捷的GUI设计,可以较为简便的实现所要求的功能。按照要求,数据输入和输出支持小数点,支持四则混合运算,决定使用如下几个数据进行分析:(1+3)*5 Sqrt(4) 1/2 Sin4 用以检验是否可以进行加减乘除四则运算、平方根、倒数、正弦的运算。 2.程序设计 M atlab的程序设计较为简便,用GUI设计出一个计算器的模型,然后系统会自动生成一个框架,在框架中,写入每一个按键对应的程序就可以实现功能。 3.调式分析 编程的过程中遇到的问题不是很多,基本就是找要实现各个功能的子程序,通过上网和去图书馆,加上自己的编写,终于实现了实验要求的功能。但是有一点很重要,matlab不支持中文,所以从路径到文件名必须是全英文的,不然就无法识别。此外,给每个按键命名也是很重要的,不然在生成的程序框架里面,就无法识别各个按键的作用,编写程序的时候也就无法做到一一对应。 4.使用说明 程序的使用比较简单,由于是可视化界面,直接打开matlab,然后建立一个GUI 工程,再打开生成的fig文件,就是一个计算器的界面,直接按照市面上卖的计算器的

方法,按键使用即可。 5.测试结果 计算结果为20 4sqrt=2 Sin4结果为 1/2=0.5 经过计算,这些结果均与实际结果相吻合,计算器的功能实现的较为完好。 6.心得体会 本次试验由于不限制语言,于是计算功能强大,操作简便的matlab变成了首选,matlab的GUI设计,操作是较为简单的,首先建立一个GUI工程,然后用可视化界面,

基于MATLAB的潮流计算源程序代码(优.选)

%*************************电力系统直角坐标系下的牛顿拉夫逊法潮流计算********** clear clc load E:\data\IEEE014_Node.txt Node=IEEE014_Node; weishu=size(Node); nnum=weishu(1,1); %节点总数 load E:\data\IEEE014_Branch.txt branch=IEEE014_Branch; bwei=size(branch); bnum=bwei(1,1); %支路总数 Y=(zeros(nnum)); Sj=100; %********************************节点导纳矩阵******************************* for m=1:bnum; s=branch(m,1); %首节点 e=branch(m,2); %末节点 R=branch(m,3); %支路电阻 X=branch(m,4); %支路电抗 B=branch(m,5); %支路对地电纳 k=branch(m,6); if k==0 %无变压器支路情形 Y(s,e)=-1/(R+j*X); %互导纳 Y(e,s)=Y(s,e); end if k~=0 %有变压器支路情形 Y(s,e)=-(1/((R+j*X)*k)); Y(e,s)=Y(s,e); Y(s,s)=-(1-k)/((R+j*X)*k^2); Y(e,e)=-(k-1)/((R+j*X)*k); %对地导纳 end Y(s,s)=Y(s,s)-j*B/2; Y(e,e)=Y(e,e)-j*B/2; %自导纳的计算情形 end for t=1:nnum; Y(t,t)=-sum(Y(t,:))+Node(t,12)+j*Node(t,13); %求支路自导纳 end G=real(Y); %电导 B=imag(Y); %电纳 %******************节点分类************************************* * pq=0; pv=0; blancenode=0; pqnode=zeros(1,nnum); pvnode=zeros(1,nnum); for m=1:nnum; if Node(m,2)==3 blancenode=m; %平衡节点编号 else if Node(m,2)==0 pq=pq+1; pqnode(1,pq)=m; %PQ 节点编号 else if Node(m,2)==2 pv=pv+1; pvnode(1,pv)=m; %PV 节点编号 end end end end %*****************************设置电压初值********************************** Uoriginal=zeros(1,nnum); %对各节点电压矩阵初始化 for n=1:nnum Uoriginal(1,n)=Node(n,9); %对各点电压赋初值 if Node(n,9)==0;

基本粒子群算法的matlab源程序

主函数源程序(main.m) %------基本粒子群优化算法(Particle Swarm Optimization)----------- %------名称:基本粒子群优化算法(PSO) %------作用:求解优化问题 %------说明:全局性,并行性,高效的群体智能算法 %------初始格式化-------------------------------------------------- clear all; clc; format long; %------给定初始化条件---------------------------------------------- c1=1.4962; %学习因子1 c2=1.4962; %学习因子2 w=0.7298; %惯性权重 MaxDT=1000; %最大迭代次数 D=10; %搜索空间维数(未知数个数) N=40; %初始化群体个体数目 eps=10^(-6); %设置精度(在已知最小值时候用) %------初始化种群的个体(可以在这里限定位置和速度的范围)------------ for i=1:N for j=1:D x(i,j)=randn; %随机初始化位置 v(i,j)=randn; %随机初始化速度 end end %------先计算各个粒子的适应度,并初始化Pi和Pg---------------------- for i=1:N p(i)=fitness(x(i,:),D); y(i,:)=x(i,:); end pg=x(1,:); %Pg为全局最优 for i=2:N if fitness(x(i,:),D) pg=x(i,:); end end %------进入主要循环,按照公式依次迭代,直到满足精度要求------------ for t=1:MaxDT for i=1:N v(i,:)=w*v(i,:)+c1*rand*(y(i,:)-x(i,:))+c2*rand*(pg-x(i,:)); x(i,:)=x(i,:)+v(i,:); if fitness(x(i,:),D) p(i)=fitness(x(i,:),D); y(i,:)=x(i,:);

Matlab实现HHT程序(源码,非常珍贵)

clear all; x=load ('06514135360001170106.TXT'); fs=1000000; N=length(x); t=0:1/fs:(N-1)/fs; z=x; c=emd(z); %计算每个IMF分量及最后一个剩余分量residual与原始信号的相关性[m,n]=size(c); for i=1:m; a=corrcoef(c(i,:),z); xg(i)=a(1,2); end xg; for i=1:m-1 %-------------------------------------------------------------------- %计算各IMF的方差贡献率 %定义:方差为平方的均值减去均值的平方 %均值的平方 %imfp2=mean(c(i,:),2).^2 %平方的均值 %imf2p=mean(c(i,:).^2,2) %各个IMF的方差 mse(i)=mean(c(i,:).^2,2)-mean(c(i,:),2).^2; end; mmse=sum(mse); for i=1:m-1 mse(i)=mean(c(i,:).^2,2)-mean(c(i,:),2).^2; %方差百分比,也就是方差贡献率 mseb(i)=mse(i)/mmse*100; %显示各个IMF的方差和贡献率 end; %画出每个IMF分量及最后一个剩余分量residual的图形 figure(1) for i=1:m-1 disp(['imf',int2str(i)]) ;disp([mse(i) mseb(i)]); end; subplot(m+1,1,1) plot(t,z) set(gca,'fontname','times New Roman') set(gca,'fontsize',14.0) ylabel(['signal','Amplitude']) for i=1:m-1 subplot(m+1,1,i+1);

BP神经网络matlab源程序代码

close all clear echo on clc % NEWFF——生成一个新的前向神经网络 % TRAIN——对 BP 神经网络进行训练 % SIM——对 BP 神经网络进行仿真 % 定义训练样本 % P为输入矢量 P=[0.7317 0.6790 0.5710 0.5673 0.5948;0.6790 0.5710 0.5673 0.5948 0.6292; ... 0.5710 0.5673 0.5948 0.6292 0.6488;0.5673 0.5948 0.6292 0.6488 0.6130; ... 0.5948 0.6292 0.6488 0.6130 0.5654; 0.6292 0.6488 0.6130 0.5654 0.5567; ... 0.6488 0.6130 0.5654 0.5567 0.5673;0.6130 0.5654 0.5567 0.5673 0.5976; ... 0.5654 0.5567 0.5673 0.5976 0.6269;0.5567 0.5673 0.5976 0.6269 0.6274; ... 0.5673 0.5976 0.6269 0.6274 0.6301;0.5976 0.6269 0.6274 0.6301 0.5803; ... 0.6269 0.6274 0.6301 0.5803 0.6668;0.6274 0.6301 0.5803 0.6668 0.6896; ... 0.6301 0.5803 0.6668 0.6896 0.7497]; % T为目标矢量 T=[0.6292 0.6488 0.6130 0.5654 0.5567 0.5673 0.5976 ... 0.6269 0.6274 0.6301 0.5803 0.6668 0.6896 0.7497 0.8094]; % Ptest为测试输入矢量 Ptest=[0.5803 0.6668 0.6896 0.7497 0.8094;0.6668 0.6896 0.7497 0.8094 0.8722; ... 0.6896 0.7497 0.8094 0.8722 0.9096]; % Ttest为测试目标矢量 Ttest=[0.8722 0.9096 1.0000]; % 创建一个新的前向神经网络 net=newff(minmax(P'),[12,1],{'logsig','purelin'},'traingdm'); % 设置训练参数 net.trainParam.show = 50; net.trainParam.lr = 0.05; net.trainParam.mc = 0.9; net.trainParam.epochs = 5000; net.trainParam.goal = 0.001; % 调用TRAINGDM算法训练 BP 网络 [net,tr]=train(net,P',T); % 对BP网络进行仿真 A=sim(net,P'); figure; plot((1993:2007),T,'-*',(1993:2007),A,'-o'); title('网络的实际输出和仿真输出结果,*为真实值,o为预测值'); xlabel('年份'); ylabel('客运量'); % 对BP网络进行测试 A1=sim(net,Ptest');

Matlab源程序代码

正弦波的源程序: (一),用到的函数 1,f2t函数 function x=f2t(X) global dt df t f T N %x=f2t(X) %x为时域的取样值矢量 %X为x的傅氏变换 %X与x长度相同并为2的整幂 %本函数需要一个全局变量dt(时域取样间隔) X=[X(N/2+1:N),X(1:N/2)]; x=ifft(X)/dt; end 2,t2f函数。 function X=t2f(x) global dt df N t f T %X=t2f(x) %x为时域的取样值矢量 %X为x的傅氏变换 %X与x长度相同,并为2的整幂。 %本函数需要一个全局变量dt(时域取样间隔) H=fft(x); X=[H(N/2+1:N),H(1:N/2)]*dt; end (二),主程序。 1,%(1)绘出正弦信号波形及频谱 global dt df t f N close all k=input('取样点数=2^k, k取10左右'); if isempty(k), k=10; end f0=input('f0=取1(kz)左右'); if isempty(f0), f0=1; end N=2^k; dt=0.01; %ms df=1/(N*dt); %KHz T=N*dt; %截短时间

Bs=N*df/2; %系统带宽 f=[-Bs+df/2:df:Bs]; %频域横坐标 t=[-T/2+dt/2:dt:T/2]; %时域横坐标 s=sin(2*pi*f0*t); %输入的正弦信号 S=t2f(s); %S是s的傅氏变换 a=f2t(S); %a是S的傅氏反变换 a=real(a); as=abs(S); subplot(2,1,1) %输出的频谱 plot(f,as,'b'); grid axis([-2*f0,+2*f0,min(as),max(as)]) xlabel('f (KHz)') ylabel('|S(f)| (V/KHz)') %figure(2) subplot(2,1,2) plot(t,a,'black') %输出信号波形画图grid axis([-2/f0,+2/f0,-1.5,1.5]) xlabel('t(ms)') ylabel('a(t)(V)') gtext('频谱图') 最佳基带系统的源程序: (一),用到的函数 f2t函数和t2f函数。代码>> (二),主程序 globaldt t f df N T close all clear Eb_N0 Pe k=input('取样点数=2^k, k取13左右'); if isempty(k), k=13; end z=input('每个信号取样点数=2^z, z

求最小费用最大流算法的MATLAB 程序代码

求最小费用最大流算法的MATLAB 程序代码如下(算例): n=5; C=[0 15 16 0 0 0 0 0 13 14 0 11 0 17 0 0 0 0 0 8 0 0 0 0 0]; %弧容量 b=[0 4 1 0 0 0 0 0 6 1 0 2 0 3 0 0 0 0 0 2 0 0 0 0 0]; %弧上单位流量的费用 wf=0;wf0=Inf; %wf 表示最大流量, wf0 表示预定的流量值 for(i=1:n)for(j=1:n)f(i,j)=0;end;end %取初始可行流f 为零流 while(1) for(i=1:n)for(j=1:n)if(j~=i)a(i,j)=Inf;end;end;end%构造有向赋权图 for(i=1:n)for(j=1:n)if(C(i,j)>0&f(i,j)==0)a(i,j)=b(i,j); elseif(C(i,j)>0&f(i,j)==C(i,j))a(j,i)=-b(i,j); elseif(C(i,j)>0)a(i,j)=b(i,j);a(j,i)=-b(i,j);end;end;end for(i=2:n)p(i)=Inf;s(i)=i;end %用Ford 算法求最短路, 赋初值 for(k=1:n)pd=1; %求有向赋权图中vs 到vt 的最短路 for(i=2:n)for(j=1:n)if(p(i)>p(j)+a(j,i))p(i)=p(j)+a(j,i);s(i)=j;pd=0;end;end;end if(pd)break;end;end %求最短路的Ford 算法结束 if(p(n)==Inf)break;end %不存在vs 到vt 的最短路, 算法终止. 注意在求最小费用最大流时构造有 向赋权图中不会含负权回路, 所以不会出现k=n dvt=Inf;t=n; %进入调整过程, dvt 表示调整量 while(1) %计算调整量 if(a(s(t),t)>0)dvtt=C(s(t),t)-f(s(t),t); %前向弧调整量 elseif(a(s(t),t)<0)dvtt=f(t,s(t));end %后向弧调整量 if(dvt>dvtt)dvt=dvtt;end if(s(t)==1)break;end %当t 的标号为vs 时, 终止计算调整量 t=s(t);end %继续调整前一段弧上的流f pd=0;if(wf+dvt>=wf0)dvt=wf0-wf;pd=1;end%如果最大流量大于或等于预定的流量值 t=n;while(1) %调整过程 if(a(s(t),t)>0)f(s(t),t)=f(s(t),t)+dvt; %前向弧调整 elseif(a(s(t),t)<0)f(t,s(t))=f(t,s(t))-dvt;end %后向弧调整 if(s(t)==1)break;end %当t 的标号为vs 时, 终止调整过程 t=s(t);end if(pd)break;end %如果最大流量达到预定的流量值 wf=0; for(j=1:n)wf=wf+f(1,j);end;end %计算最大流量 zwf=0;for(i=1:n)for(j=1:n)zwf=zwf+b(i,j)*f(i,j);end;end %计算最小费用 f %显示最小费用最大流 wf %显示最小费用最大流量 zwf %显示最小费用, 程序结束

主成分分析matlab源程序代码

263.862 1.61144 2.754680.266575 268.764 2.07218 2.617560.182597 261.196 1.59769 2.350370.182114 248.708 2.09609 2.852790.257724 253.365 1.69457 2.94920.189702 268.434 1.56819 2.781130.13252 258.741 2.14653 2.691110.136469 244.192 2.02156 2.226070.298066 219.738 1.61224 1.885990.166298 244.702 1.91477 2.259450.187569 245.286 2.12499 2.352820.161602 251.96 1.83714 2.535190.240271 251.164 1.74167 2.629610.211887 251.824 2.00133 2.626650.211991 257.68 2.14878 2.656860.203846] stdr=std(dataset);%求个变量的标准差 [n,m]=size(dataset);%定义矩阵行列数 sddata=dataset./stdr(ones(n,1),:);%将原始数据采集标准化 sddata%输出标准化数据 [p,princ,eigenvalue,t2]=princomp(sddata);%调用前三个主成分系数 p3=p(:,1:3);%提取前三个主成分得分系数,通过看行可以看出对应的原始数据的列,每个列在每个主成分的得分 p3%输出前三个主成分得分系数 sc=princ(:,1:3);%提取前三个主成分得分值 sc%输出前三个主成分得分值 e=eigenvalue(1:3)';%提取前三个特征根并转置 M=e(ones(m,1),:).^0.5;%输出前三个特征根并转置 compmat=p3.*M;%利用特征根构造变换矩阵 per=100*eigenvalue/sum(eigenvalue);%求出成分载荷矩阵的前三列 per %求出各主成分的贡献率 cumsum(per);%列出各主成分的累积贡献率 figure(1) pareto(per);%将贡献率绘成直方图 t2 figure(2) %输出各省与平局距离 plot(eigenvalue,'r+');%绘制方差贡献散点图 hold on %保持图形 plot(eigenvalue,'g-');%绘制方差贡献山麓图

gmres源程序matlab

f u n c t i o n[x,f l a g,r e l r e s,i t e r,r e s v e c]= g m r e s(A,b,r e s t a r t,t o l,m a x i t,M1,M2,x,v a r a r g i n) %GMRES Generalized Minimum Residual Method. % X = GMRES(A,B) attempts to solve the system of linear equations A*X = B % for X. The N-by-N coefficient matrix A must be square and the right % hand side column vector B must have length N. This uses the unrestarted % method with MIN(N,10) total iterations. % % X = GMRES(AFUN,B) accepts a function handle AFUN instead of the matrix % A. AFUN(X) accepts a vector input X and returns the matrix-vector % product A*X. In all of the following syntaxes, you can replace A by % AFUN. % % X = GMRES(A,B,RESTART) restarts the method every RESTART iterations. % If RESTART is N or [] then GMRES uses the unrestarted method as above. % % X = GMRES(A,B,RESTART,TOL) specifies the tolerance of the method. If % TOL is [] then GMRES uses the default, 1e-6. % % X = GMRES(A,B,RESTART,TOL,MAXIT) specifies the maximum number of outer % iterations. Note: the total number of iterations is RESTART*MAXIT. If % MAXIT is [] then GMRES uses the default, MIN(N/RESTART,10). If RESTART % is N or [] then the total number of iterations is MAXIT. % % X = GMRES(A,B,RESTART,TOL,MAXIT,M) and % X = GMRES(A,B,RESTART,TOL,MAXIT,M1,M2) use preconditioner M or M=M1*M2 % and effectively solve the system inv(M)*A*X = inv(M)*B for X. If M is % [] then a preconditioner is not applied. M may be a function handle % returning M\X. % % X = GMRES(A,B,RESTART,TOL,MAXIT,M1,M2,X0) specifies the first initial % guess. If X0 is [] then GMRES uses the default, an all zero vector. % % [X,FLAG] = GMRES(A,B,...) also returns a convergence FLAG: % 0 GMRES converged to the desired tolerance TOL within MAXIT iterations. % 1 GMRES iterated MAXIT times but did not converge. % 2 preconditioner M was ill-conditioned. % 3 GMRES stagnated (two consecutive iterates were the same). % % [X,FLAG,RELRES] = GMRES(A,B,...) also returns the relative residual % NORM(B-A*X)/NORM(B). If FLAG is 0, then RELRES <= TOL. Note with % preconditioners M1,M2, the residual is NORM(M2\(M1\(B-A*X))). % % [X,FLAG,RELRES,ITER] = GMRES(A,B,...) also returns both the outer and % inner iteration numbers at which X was computed: 0 <= ITER(1) <= MAXIT % and 0 <= ITER(2) <= RESTART. %

Matlab程序代码

Matlab程序代码 function [seg]=MRMRF(w,class_number,potential,maxIter) %MRMRF图像分割算法 %w-待分解图像的多尺度序列 %class_number-分类数 %potential-potts模型势函数 %maxIter-最大迭代次数 %多分辨率表达的尺度数 L=size(w,1); %分割结果的多尺度序列 seg=cell(L,1); %使用ICM算法计算最高尺度的分割结果 seg{ L }=ICM(w{ L },class_number,potential,maxIter); %计算其他尺度的分割结果 for n=(L-1):-1:1 %获取初始分割结果 segn=myZoomOut(seg{ n+1 }); %获取尺度n上的最终分割结果 wn=w{ n }; segn=ICMn(wn,segn,class_number,potential,maxIter); %保存尺度n上的分割结果 seg{ n }=segn; end end function [seg]=ICMn(image,seg,class_number,potential,maxIter) %尺度n上已知初始结果的ICM分割 [width,height,bands]=size(image); %将图像和初始分割结果分别转换为向量 image=imstack2vectors(image); seg=imstack2vectors(seg); %ICM迭代

iter=0; while(iter

matlab经典代码大全

哈哈哈 MATLAB 显示正炫余炫图:plot(x,y1,'* r',x,y2,'o b') 定义【0,2π】;t=0:pi/10:2*pi; 定义函数文件:function [返回变量列表]=函数名(输入变量列表) 顺序结构:选择结构 1)if-else-end语句 其格式为: if 逻辑表达式 程序模块1; else 程序模块2; End 图片读取:%选择图片路径 [filename, pathname] = ... uigetfile({'*.jpg';'*.bmp';'*.gif'},'选择图片'); %合成路径+文件名 str=[pathname,filename]; %为什么pathname和filename要前面出现的位置相反才能运行呢???%读取图片 im=imread(str); %使用图片 axes(handles.axes1); %显示图片 imshow(im); 边缘检测: global im str=get(hObject,'string'); axes (handles.axes1); switch str case ' 原图' imshow(im); case 'sobel' BW = edge(rgb2gray(im),'sobel'); imshow(BW); case 'prewitt' BW = edge(rgb2gray(im),'prewitt');

imshow(BW); case 'canny' BW = edge(rgb2gray(im),'canny'); imshow(BW);Canny算子边缘定位精确性和抗噪声能力效果较好,是一个折中方案 end; 开闭运算: se=[1,1,1;1,1,1;1,1,1;1,1,1]; %Structuring Element I=rgb2gray(im); imshow(I,[]);title('Original Image'); I=double(I); [im_height,im_width]=size(I); [se_height,se_width]=size(se); halfheight=floor(se_height/2); halfwidth=floor(se_width/2); [se_origin]=floor((size(se)+1)/2); image_dilation=padarray(I,se_origin,0,'both'); %Image to be used for dilation image_erosion=padarray(I,se_origin,256,'both'); %Image to be used for erosion %%%%%%%%%%%%%%%%%% %%% Dilation %%% %%%%%%%%%%%%%%%%%% for k=se_origin(1)+1:im_height+se_origin(1) for kk=se_origin(2)+1:im_width+se_origin(2) dilated_image(k-se_origin(1),kk-se_origin(2))=max(max(se+image_dilation(k-se_origin(1):k+halfh eight-1,kk-se_origin(2):kk+halfwidth-1))); end end figure;imshow(dilated_image,[]);title('Image after Dilation'); %%%%%%%%%%%%%%%%% %%% Erosion %%% %%%%%%%%%%%%%%%%% se=se'; for k=se_origin(2)+1:im_height+se_origin(2) for kk=se_origin(1)+1:im_width+se_origin(1) eroded_image(k-se_origin(2),kk-se_origin(1))=min(min(image_erosion(k-se_origin(2):k+halfwidth -1,kk-se_origin(1):kk+halfheight-1)-se)); end end figure;imshow(eroded_image,[]);title('Image after Erosion'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Opening(Erosion first, then Dilation) %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

2048游戏matlab代码

说明:本代码为2048游戏matlab代码,程序未进行游戏结束判定,节目如下。 function g2048(action) global totalscore flag score_board if nargin<1 figure_h=figure; set(figure_h,'Units','points') set(figure_h,'UserData',figure_h); totalscore=0; flag=0; score_board=zeros(1,16); action='initialize'; end switch action case'initialize'; figure_h=get(gcf,'UserData'); set(figure_h,... 'Color',[0.4 0.4 0.4],... 'Menubar','none',... 'Name','2048',... 'NumberTitle','off',... 'Position',[200 200 320 355],... 'Resize','off'); axis('off') game_score=uicontrol(figure_h,... 'BackgroundColor',[1 1 1],... 'ForegroundColor',[0 0 0], ... 'HorizontalAlignment','center',... 'FontSize',12,... 'Units','points',... 'Position',[235 305 65 30],... 'String','Score',... 'Style','edit',... 'Tag','game_score'); new_game_h=uicontrol(figure_h,...

相关主题
相关文档
最新文档