第一篇:2009全國(guó)數(shù)學(xué)建模大賽學(xué)習(xí)總結(jié)~MATLAB
全國(guó)數(shù)學(xué)建模大賽過去挺長(zhǎng)時(shí)間了,今天想要寫點(diǎn)關(guān)于MATLAB應(yīng)用技巧的小總結(jié)。不得不承認(rèn)MATLAB實(shí)在是太強(qiáng)大了,有太多的工具箱。我先簡(jiǎn)單的介紹一下,在數(shù)學(xué)建模中,我用到的一些比較方便的命令,和大家分享一下。
Plottools:MATLAB作圖工具箱
可以畫出二維和三維圖像
如果你已經(jīng)打開圖形窗口了, 可以通過點(diǎn)擊'快捷按鈕欄'中最右側(cè)那個(gè)圖標(biāo)啟動(dòng)Plottools;若還沒有打開任何圖形窗口, 可以在Matlab的命令窗口(command window)中輸入命令: plottools 就可以打開一個(gè)新圖形窗口, 同時(shí)也啟動(dòng)Plottools工具;還有一種情況, 你已經(jīng)打開一個(gè)plottools窗口, 但是想要同時(shí)再畫另一個(gè)圖像, 那么, 可以在已有的圖像窗口中點(diǎn)擊'新建'按鈕, 新建一個(gè)圖形窗口, 然后在那個(gè)窗口上點(diǎn)擊最右側(cè)圖標(biāo)來激活plottools工具。左側(cè)從上到下依次是:
? 1.添加新的坐標(biāo)系:
向中間的圖形窗口內(nèi)添加新的坐標(biāo)系, 可選二維或三維坐標(biāo)系, 甚至可以一次選擇多個(gè)坐標(biāo)系, 如果不預(yù)先選擇坐標(biāo)系而是直接添加圖形, Matlab會(huì)自動(dòng)添加一個(gè)合適的坐標(biāo)系
? 2.變量列表: Matlab當(dāng)前工作空間(workspace)中存在的變量列表于此, 通過在變量上點(diǎn)擊右鍵, 激活右鍵彈出菜單, 我們可以畫相應(yīng)變量的圖像, 但是不推薦這么做, 因?yàn)檫@樣畫圖沒有控制選項(xiàng), 容易出錯(cuò), 我們還有更好的辦法
3.標(biāo)識(shí)圖形: 向已畫號(hào)的圖像中添加表示圖形, 如線條, 箭頭等 說明:
2D Axes 得到二維圖像 3D Axes 得到三維圖像 plot(y)得到普通函數(shù)圖像 bar(y)得到樹干圖 stem(y)得到階梯圖 area(y)得到區(qū)域圖
pie(y)得到對(duì)應(yīng)百分比的餅圖 hist(y)得到以上6種圖像合并的圖像
cftool:擬合工具箱
cftool 進(jìn)入其介面就是近乎傻瓜式的擬合操作了 進(jìn)入曲線擬合工具箱界面“Curve Fitting tool”(1)點(diǎn)擊“Data”按鈕,彈出“Data”窗口;
(2)利用X data和Y data的下拉菜單讀入數(shù)據(jù)x,y,可修改數(shù)據(jù)集名“Data set name”,然后點(diǎn)擊“Create data set”按鈕,退出“Data”窗口,返回工具箱界面,這時(shí)會(huì)自動(dòng)畫出數(shù)據(jù)集的曲線圖;
(3)點(diǎn)擊“Fitting”按鈕,彈出“Fitting”窗口;
(4)點(diǎn)擊“New fit”按鈕,可修改擬合項(xiàng)目名稱“Fit name”,通過“Data set”下拉菜單選擇數(shù)據(jù)集,然后通過下拉菜單“Type of fit”選擇擬合曲線的類型,工具箱提供的擬合類型有:
· Custom Equations:用戶自定義的函數(shù)類型
·Exponential:指數(shù)逼近,有2種類型,a*exp(b*x)、a*exp(b*x)+ c*exp(d*x)· Fourier:傅立葉逼近,有7種類型,基礎(chǔ)型是 a0 + a1*cos(x*w)+ b1*sin(x*w)· Gaussian:高斯逼近,有8種類型,基礎(chǔ)型是 a1*exp(-((x-b1)/c1)^2)
·Interpolant:插值逼近,有4種類型,linear、nearest neighbor、cubic spline、shape-preserving · Polynomial:多形式逼近,有9種類型,linear ~、quadratic ~、cubic ~、4-9th degree ~
·Power:冪逼近,有2種類型,a*x^b、a*x^b + c
·Rational:有理數(shù)逼近,分子、分母共有的類型是linear ~、quadratic ~、cubic ~、4-5th degree ~;此外,分子還包括constant型
· Smoothing Spline:平滑逼近(翻譯的不大恰當(dāng),不好意思)
·Sum of Sin Functions:正弦曲線逼近,有8種類型,基礎(chǔ)型是 a1*sin(b1*x + c1)· Weibull:只有一種,a*b*x^(b-1)*exp(-a*x^b)
這個(gè)命令特別好用,今年建模比賽,我就是用了這個(gè)命令做的轉(zhuǎn)矩與轉(zhuǎn)速的關(guān)系圖,并進(jìn)行了擬合,很好用的。
disttool:常用的分布函數(shù):
disttool
輸入該命令可以直接得到一些常用函數(shù)的圖像,像beta(百特分布),binomial(二項(xiàng)式分布)。。。。
好了,先寫這些吧,MATLAB很強(qiáng)大,有些命令知道了 就可以省去很多 自己的編程
學(xué)無止境,加油吧
希望這些所謂的技巧能給大家?guī)矸奖?/p>
第二篇:數(shù)學(xué)建模常用的Matlab繪圖總結(jié)
餅狀圖
Expenses = [20 10 40 12 20 19 5 15];
ExpenseCategories = {'Food','Medical','Lodging','Incidentals',...'Transport','Utilities','Gifts','Shopping'};
MostLeastExpensive =(Expenses==max(Expenses)|Expenses==min(Expenses));
h=pie(gca,Expenses,MostLeastExpensive,ExpenseCategories);
ShoppingGiftsFoodMedicalUtilitiesTransportLodgingIncidentalsExpenses = [20 10 40 12 20 19 5 15];
MostLeastExpensive =(Expenses==max(Expenses)|Expenses==min(Expenses));
h=pie(gca,Expenses,MostLeastExpensive);legend('Food','Medical','Lodging','Incidentals',...'Transport','Utilities','Gifts','Shopping');
4%FoodMedicalLodgingIncidentalsTransportUtilitiesGiftsShopping
14%11%7%13%14%28% 9% Expenses = [20 10 40 12 20 19 5 15];
MostLeastExpensive = [0 1 0 1 0 1 0 1];%分割 h=pie(gca,Expenses,MostLeastExpensive);legend('Food','Medical','Lodging','Incidentals',...'Transport','Utilities','Gifts','Shopping');
11%14%4%7%13% FoodMedicalLodgingIncidentalsTransportUtilitiesGiftsShopping28%14% 9%
x = [20 10 40 12 20 19 5 15];explode = [4 2 2 2 2 4 2 2];label = {'Food','Medical','Lodging','Incidentals',...'Transport','Utilities','Gifts','Shopping',}';figure('color','w','renderer','openGL');h = pie3(x,explode);h = findobj(h,'Type','text');set(h,{'string'},cellfun(@strcat,get(h,{'string'}),label,'un',0),'FontName','Times New Roman','FontSize',16);%set(h,{'string'},strcat(get(h,{'string'}),label));
%cm = [72 65 137;143 184 58;193 60 49;41 121 201;...%
150;189 84 58;193 160 90;241 121 101]/255;colormap(jet), shading interp view(18,20), camproj perspective light('Position',[1 2 3],'Style','inf')lighting gouraud
x = [20 10 40 12 20 19 5 15];explode = [4 2 2 2 2 4 2 2];label = {'14% Food','7% Medical','28% Lodging','9% Incidentals',...'14% Transport','13% Utilities','4% Gifts','11% Shopping',}';figure('color','w','renderer','openGL');pie3s(x,'Explode',explode,'Labels',label)%見Matlab_pie3s
直方圖
Y = round(rand(5,3)*10);figure;subplot(2,2,1);bar(Y,'grouped');title('Group')subplot(2,2,2);bar(Y,'stacked');title('Stack')subplot(2,2,3);bar(Y,'histc');title('Histc')subplot(2,2,4);bar(Y,'hist');title('Hist')Group105100123Histc10501050450123Hist453020Stack1234512345
stream = RandStream('mrg32k3a','Seed',4);y1 = rand(stream,10,5);hb = bar(y1,'stacked');colormap(summer);hold on y2 = rand(stream,10,1);set(gca,'FontSize',14,'FontName','Times New Roman')hp = plot(1:10,y2,'marker','square','markersize',12,...'markeredgecolor','y','markerfacecolor',[.6,0,.6],...'linestyle','-','color','r','linewidth',2);hold off legend([hb,hp],'Carrots','Peas','Peppers','Green Beans',...'Cucumbers','Eggplant','Location','SouthEastOutside')3.532.521.510.50 12345678910CarrotsPeasPeppersGreen BeansCucumbersEggplant Data = [1,-2,3,1,-1,-2 4 2 3];DataP = Data;DataN = Data;DataP(Data < 0)= 0;DataN(Data > 0)= 0;figure;bar(DataP,0.5,'k','EdgeColor','k');hold on;bar(DataN,0.5,'b','EdgeColor','b');43210-1-2123456789
Y = round(rand(5,3)*10);figure;subplot(2,2,1);bar3(Y,'grouped');
title('Group','FontSize',14,'FontName','Times New Roman')subplot(2,2,2);bar3(Y,'stacked');
title('Stack','FontSize',14,'FontName','Times New Roman')subplot(2,2,3);bar3(Y,'histc');
title('Histc','FontSize',14,'FontName','Times New Roman')subplot(2,2,4);bar3(Y,'hist');
title('Hist','FontSize',14,'FontName','Times New Roman')
Group1020Stack***Histc1010Hist***45123
桿狀圖
Data = [1,-2,3,1,-1,-2 4 2 3];DataP = Data;DataN = Data;DataP(Data < 0)= NaN;DataN(Data > 0)= NaN;figure;stem(DataP,'k');hold on;stem(DataN,'b');43210-1-2123456789Data = [1,-2,3,1,-1,-2 4 2 3];DataP = Data;DataN = Data;DataP(Data < 0)= NaN;DataN(Data > 0)= NaN;figure;stem(DataP,'k','fill');hold on;stem(DataN,'b','fill');4
3210-1-2123456789 Data = [1,-2,3,1,-1,-2 4 2 3];DataP = Data;DataN = Data;DataP(Data < 0)= NaN;DataN(Data > 0)= NaN;figure;stem(DataP,':diamondk','fill');hold on;stem(DataN,':diamondr','fill');43210-1-2123456789
Data = [1,-2,3,1,-1,-2 4 2 3];DataP = Data;DataN = Data;DataP(Data < 0)= NaN;DataN(Data > 0)= NaN;figure;stem(DataP,'LineStyle','-.','MarkerFaceColor','k','MarkerEdgeColor','green');hold on;stem(DataN,'LineStyle','-.','MarkerFaceColor','red','MarkerEdgeColor','green');4
3210-1-2123456789
三維圖形
figure;[X,Y] = meshgrid(-15:.5:15,-12:.5:12);%X belongs to [-15,15] and Y belongs to [-12,12].R = sqrt(X.^2 + Y.^2)+ eps;Z = sin(R)./R;mesh(Z);%surf(X,Y,Z)
xlabel('X','FontSize',14,'FontName','Times New Roman')ylabel('Y','FontSize',14,'FontName','Times New Roman')zlabel('Z','FontSize',14,'FontName','Times New Roman')title('3-D space','FontSize',16,'FontName','Times New Roman')
3-D space by mesh10.5Z0-0.***203040506070YX
figure;X=-12:0.5:12;Y=-12:0.5:12;%surf繪圖時(shí),X,Y可以是一維向量,也可以是二維矩陣 R=ones(length(X),length(Y));for i=1:length(X)
for j=1:length(Y)
R(i,j)= sqrt(X(i).^2 + Y(j).^2)+eps;
end end
Z = sin(R)./R;surf(X,Y,Z);xlabel('X','FontSize',14,'FontName','Times New Roman')ylabel('Y','FontSize',14,'FontName','Times New Roman')zlabel('Z','FontSize',14,'FontName','Times New Roman')title('3-D space by surf','FontSize',16,'FontName','Times New Roman')
3-D space by surf10.5Z0-0.5151050-5-10-15-15-10-5051015YX
figure;[X,Y] = meshgrid(-15:.5:15,-12:.5:12);%X belongs to [-15,15] and Y belongs to [-12,12].R = sqrt(X.^2 + Y.^2)+ eps;Z = sin(R)./R;plot3(X,Y,Z);xlabel('X','FontSize',14,'FontName','Times New Roman')ylabel('Y','FontSize',14,'FontName','Times New Roman')zlabel('Z','FontSize',14,'FontName','Times New Roman')title('3-D space by plot3','FontSize',16,'FontName','Times New Roman')
3-D space by plot310.5Z0-0.5151050-5-10-5051015Y-15-15-10X
數(shù)學(xué)公式、符號(hào)和希臘字母的輸入命令
Character Sequence alpha beta gamma delta epsilon zeta eta theta vartheta iota kappa lambda mu nu xi pi rho sigma varsigma tau equiv Im otimes cap supset int rfloor lfloor perp wedge rceil vee langle Symbol α β γ δ ? δ ε Θ ? ι κ λ μ ν ξ π π σ ρ τ ≡ ?
? ∩ ?
∫ ? ? ⊥
∧
ù ∨ ∠
Character Sequence upsilon phi chi psi omega Gamma Delta Theta Lambda Xi Pi Sigma Upsilon Phi Psi Omega forall exists ni cong approx Re oplus cup
subseteq in lceil cdot neg times surd varpi rangle
Symbol ? Φ σ τ υ Γ Δ Θ Λ Ξ Π Σ ? Φ Ψ Ω ? ? ? ? ≈ ? ⊕ ∪
? ∈ é · ? x √ ? ∠ Character Sequence sim leq infty clubsuit diamondsuit heartsuit spadesuit leftrightarrow leftarrow uparrow rightarrow downarrow circ pm geq propto partial bullet div neq aleph wp oslash supseteq subset o nabla ldots prime