数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz
楼主: 宝宝

matlab与数模有关的例

[复制链接]
发表于 2004-7-6 03:37:19 | 显示全部楼层
<>非常感谢</P><>很有启发</P><>辛苦了</P>
发表于 2004-7-6 20:16:07 | 显示全部楼层
<>题目:</P><>输入一个正整数(可能大于2的32次方)给出因子分解的编程</P><>拜求各位大人</P>
发表于 2004-7-12 18:06:20 | 显示全部楼层
<>好样的</P>
发表于 2004-7-12 23:43:04 | 显示全部楼层
<DIV class=quote><B>以下是引用<I>宝宝</I>在2004-6-1 10:55:01的发言:</B>

<><B><FONT face="Times New Roman">1</FONT></B><B>.曲线拟合</B><B><FONT face="Times New Roman">    </FONT></B><B>美国人口预测</B><B>

</B>
<p>
<>1.下表是美国人口统计数据,根据这份资料预测2000年美国人口总数。
<p>
<p>
<TABLE border=1 cellPadding=0 cellSpacing=0>

<TR>
<TD vAlign=top width=91>
<><FONT size=2>年
<p></FONT>
<p></TD>
<TD vAlign=top width=350>
<P><FONT size=2>1790   1800   1810   1820   1830    1840    1850
<p></FONT>
<p></TD></TR>
<TR>
<TD vAlign=top width=91>
<P><FONT size=2>人口(百万)
<p></FONT>
<p></TD>
<TD vAlign=top width=350>
<P><FONT size=2>3.9    5.3     7.2    9.6   12.9    17.1    23.2
<p></FONT>
<p></TD></TR>
<TR>
<TD vAlign=top width=91>
<P><FONT size=2>年
<p></FONT>
<p></TD>
<TD vAlign=top width=350>
<P><FONT size=2>1860   1870   1880   1890   1900    1910    1920
<p></FONT>
<p></TD></TR>
<TR>
<TD vAlign=top width=91>
<P><FONT size=2>人口(百万)
<p></FONT>
<p></TD>
<TD vAlign=top width=350>
<P><FONT size=2>31.4   38.6    50.2   62.9  76.0    92.0    106.5
<p></FONT>
<p></TD></TR>
<TR>
<TD vAlign=top width=91>
<P><FONT size=2>年
<p></FONT>
<p></TD>
<TD vAlign=top width=350>
<P><FONT size=2>1930   1940    1950   1960  1970    1980    1990
<p></FONT>
<p></TD></TR>
<TR>
<TD vAlign=top width=91>
<P><FONT size=2>人口(百万)
<p></FONT>
<p></TD>
<TD vAlign=top width=350>
<P><FONT size=2>123.2  131.7   150.7  179.3  204.0  226.5   251.4
<p></FONT>
<p></TD></TR></TABLE>
<P><FONT face="Times New Roman" size=3>Step 1   A=[1790,1800,1810,…;</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">           3.9,  5.3,  7.2,…]’;</FONT></FONT></P>
<P><FONT face="Times New Roman">    Step 2    P=polyfit(A(:,1),A(:,2),3)</FONT></P>
<P><FONT face="Times New Roman" size=3>Step 3   px=poly2str(P,'x')</FONT></P>
<P><FONT face="Times New Roman" size=3>Step 4   polyval(P,2000)</FONT></P>
<P>如果想了解<FONT face="Times New Roman"> fx</FONT>与数据对<FONT face="Times New Roman">x-y</FONT>的拟和程度,绘出二者的图形最为直观,为此可键入:
<p>
<p>
<P><FONT size=3><FONT face="Times New Roman">ft=polyval(P,A(:,1));plot(A(:,1),A(:,2),'bo',A(:,1),ft,'r-')</FONT>得图形。图中蓝色小圆圈是数据对的图形;而红线是拟合多项式的图形。最后,可与<FONT face="Times New Roman">demo_sensus</FONT>比较。</FONT></P>
<P><B><FONT face="Times New Roman">2.              </FONT></B><B>插值</B><B>
<p></B>
<p>
<P><FONT size=3>“线性插值”<FONT face="Times New Roman">           linear</FONT></FONT></P>
<P><FONT size=3>“三次样条插值”<FONT face="Times New Roman">       spline</FONT></FONT></P>
<P><FONT size=3>“三次多项式插值”<FONT face="Times New Roman">     cubic</FONT></FONT></P>
<P><FONT size=3>对于以上问题,也可以用这三个命令来做。</FONT></P>
<P><B><FONT face="Times New Roman">3.                  </FONT></B><B>交通流量问题</B></P>
<P><FONT size=3>下图给出了某城市部分单行街道的交通流量(每小时过车数)</FONT></P>
<P><v:line><v:stroke endarrow="block"><FONT size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT size=3></FONT></v:stroke></v:line><FONT face="Times New Roman"><FONT size=3>    x3   100      x6    </FONT></FONT></P>
<P><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><FONT face="Times New Roman"><FONT size=3>300    x4    400            200             </FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>   x2            x7   </FONT></FONT></P>
<P><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><FONT face="Times New Roman"><FONT size=3>300   x1     600            x8                       </FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>  500   200      400         </FONT></FONT></P>
<P><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><v:line><v:stroke endarrow="block"><FONT face="Times New Roman" size=3></FONT></v:stroke></v:line><FONT face="Times New Roman"><FONT size=3>300                         500             </FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>      x9    x10                    </FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>   600           700             </FONT></FONT></P>
<P><FONT size=3>所给问题满足下列方程组</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>      x1-x3+x4=300</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>         x4+x5=500</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>         x7-x6=200</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>         x1+x2=800</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>         x1+x5=800</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>         x7+x8=1000</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>         x8+x3+x6=1000         (x9=400,  x10=600)</FONT></FONT></P>
<P><FONT face="Times New Roman" size=3>Step1  A=[0,1,-1,1,0,0,0,0;</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>          0,0,0,1,1,0,0,0;</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>       0,0,0,0,0,-1,1,0;</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>       1,1,0,0,0,0,0,0;</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>       1,0,0,0,1,0,0,0;</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>       0,0,0,0,0,0,1,1;</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>       0,0,1,0,0,1,0,1];</FONT></FONT></P>
<P><FONT face="Times New Roman" size=3>Step 2   b=[300,500,200,800,800,1000,1000]’;</FONT></P>
<P><FONT face="Times New Roman" size=3>Step 3   B1=rank(A);B2=rank([A,b]);</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">Step 4   </FONT>X=linsolve(A,b)
<p></FONT>
<p>
<P><FONT size=3>得特解。
<p></FONT>
<p>
<P><B><FONT face="Times New Roman">4</FONT></B><B>.线性规划有约束极小问题</B><B>
<p></B>
<p>
<P><WRAPBLOCK><v:shapetype><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path extrusionok="f" gradientshapeok="t" connecttype="rect"></v:path><LOCK v:ext="edit" aspectratio="t"></LOCK></v:shapetype><v:shape><v:imagedata></v:imagedata><w:wrap type="topAndBottom"></w:wrap></v:shape></WRAPBLOCK><BR clear=all><FONT size=3>用命令<FONT face="Times New Roman">x=lp(C,A,b,vlb,vub)</FONT>。</FONT></P>
<P><FONT size=3>例:<FONT face="Times New Roman">Find <B>x</B> that minimizes </FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>f(<B>x</B>)=-5x<SUB>1</SUB>-4x<SUB>2</SUB>-6x<SUB>3</SUB></FONT></FONT></P>
<P><FONT face="Times New Roman" size=3>subject to</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">x<SUB>1</SUB>-x<SUB>2</SUB>+x<SUB>3</SUB></FONT>≦<FONT face="Times New Roman">20</FONT></FONT></P>
<P><FONT size=3><FONT face="Times New Roman">3x<SUB>1</SUB>+2x<SUB>2</SUB>+4x<SUB>3</SUB></FONT>≦4<FONT face="Times New Roman">2</FONT></FONT></P>
<P><FONT size=3><FONT face="Times New Roman">3x<SUB>1</SUB>+2x<SUB>2</SUB></FONT>≦<FONT face="Times New Roman">30</FONT></FONT></P>
<P><FONT size=3><FONT face="Times New Roman">0</FONT>≦<FONT face="Times New Roman">x<SUB>1</SUB>, 0</FONT>≦<FONT face="Times New Roman">x<SUB>2</SUB>,0</FONT>≦<FONT face="Times New Roman">x<SUB>3</SUB></FONT></FONT></P>
<P><FONT face="Times New Roman" size=3>First, enter the coefficients:</FONT></P>
<P><FONT face="Times New Roman" size=3>f = [-5; -4; -6]</FONT></P>
<P><FONT face="Times New Roman" size=3>A =  [1 -1  1</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>      3  2  4</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>      3  2  0];</FONT></FONT></P>
<P><FONT face="Times New Roman" size=3>b = [20; 42; 30];</FONT></P>
<P><FONT face="Times New Roman" size=3>lb = zeros(3,1);</FONT></P>
<P><FONT face="Times New Roman" size=3>Next, call a linear programming routine:</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>
<p></FONT></FONT>
<p>
<P><FONT face="Times New Roman" size=3>x= lp(f,A,b,lb);</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>
<p></FONT></FONT>
<p>
<P><FONT face="Times New Roman" size=3>Entering x</FONT></P>
<P><FONT face="Times New Roman" size=3>x = </FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>     0.0000</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>    15.0000</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>     3.0000</FONT></FONT></P>
<P><FONT size=3>实际此命令改为:<FONT face="Times New Roman"> </FONT></FONT></P>
<P><FONT face="Times New Roman" size=3>x = linprog(f,A,b,Aeq,beq)</FONT></P>
<P><FONT face="Times New Roman" size=3>x = linprog(f,A,b,Aeq,beq,lb,ub)</FONT></P>
<P><FONT size=3>对以上的问题可做如下的操作:</FONT></P>
<P><FONT face="Times New Roman" size=3>First, enter the coefficients:</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>
<p></FONT></FONT>
<p>
<P><FONT face="Times New Roman" size=3>f = [-5; -4; -6]</FONT></P>
<P><FONT face="Times New Roman" size=3>A =  [1 -1  1</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>      3  2  4</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>      3  2  0];</FONT></FONT></P>
<P><FONT face="Times New Roman" size=3>b = [20; 42; 30];</FONT></P>
<P><FONT face="Times New Roman" size=3>lb = zeros(3,1);</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>
<p></FONT></FONT>
<p>
<P><FONT face="Times New Roman" size=3>Next, call a linear programming routine:</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>
<p></FONT></FONT>
<p>
<P><FONT size=3><FONT face="Times New Roman">[x,fval,exitflag,output,lambda] = linprog(f,A,b,[],[],lb)</FONT>;</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>
<p></FONT></FONT>
<p>
<P><FONT face="Times New Roman" size=3>Entering x, fval,lambda.ineqlin, and lambda.lower gets</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>
<p></FONT></FONT>
<p>
<P><FONT face="Times New Roman" size=3>x =</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>    0.0000</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>   15.0000</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>    3.0000</FONT></FONT></P>
<P><FONT face="Times New Roman" size=3>fval =</FONT></P>
<P><FONT face="Times New Roman"><FONT size=3>  -78.0000</FONT></FONT></P>
<P><FONT size=3>和其它信息。</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">
<p></FONT></FONT>
<p>
<P><FONT size=3><FONT face="Times New Roman">
<p></FONT></FONT>
<p>
<P><B><FONT face="Times New Roman">5</FONT></B><B>.非线性规划有约束极小问题</B><B>
<p></B>
<p>
<P><WRAPBLOCK><v:shape><v:imagedata></v:imagedata><w:wrap type="topAndBottom"></w:wrap></v:shape></WRAPBLOCK><BR clear=all><FONT size=3>用命令<FONT face="Times New Roman">x=constr('f ',x0)</FONT>。</FONT></P>
<P><FONT face="Times New Roman" size=3>Examples</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">Find values of x that minimize  f(x)=-x1x2x3, starting at the point x = [10; 10; 10] and subject to the constraints  0</FONT>≤<FONT face="Times New Roman">x1+2x2+2x3</FONT>≤72.
<p></FONT>
<p>
<P><FONT size=3><FONT face="Times New Roman">-x1-2x2-2x3</FONT>≤0,<FONT face="Times New Roman">x1+2x2+2x3</FONT>≤72,
<p></FONT>
<p>
<P><FONT size=3>第一步:编写<FONT face="Times New Roman">M</FONT>文件</FONT></P>
<P><FONT face="Times New Roman" size=3>function [f,g]=myfun(x)</FONT></P>
<P><FONT face="Times New Roman" size=3>f=-x(1)*x(2)*x(3);</FONT></P>
<P><FONT face="Times New Roman" size=3>g(1)=-x(1)-2*x(2)-2*x(3);</FONT></P>
<P><FONT face="Times New Roman" size=3>g(2)=x(1)+2*x(2)+2*x(3)-72;</FONT></P>
<P><FONT size=3>第二步:求解</FONT></P>
<P><FONT size=3>在<FONT face="Times New Roman">MATLAB</FONT>工作窗中键入</FONT></P>
<P><FONT face="Times New Roman" size=3>x0=[10,10,10];</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">x=constr('myfun',x0)</FONT>即可</FONT></P>
<P><FONT size=3><FONT face="Times New Roman">
<p></FONT></FONT>
<p></DIV>
<P>是正确的,刚才天狼说错了,他没有看到后面的转置符号[<FONT face=黑体>’]</FONT></P>
发表于 2004-7-16 18:19:29 | 显示全部楼层
<DIV class=quote><B>以下是引用<I>eastwardsheng</I>在2004-6-11 21:21:54的发言:</B>
<>有谁能告诉我:怎样用<B>matlab算偏微分方程</B></P></DIV>
<>MATLAB中有偏微分方程工具箱,有几个求解偏微分方程的函数:


<>adaptmesh     生成自适应网格及偏微分方程的解;
hyperbolic      求解双曲线型偏微分方程;
parabolic        求解抛物线型偏微分方程;
pdeeig           求解特征型偏微分方程;
pdenonlin       求解非线性偏微分方程;
poisolv           利用矩阵格式快速求解泊松方程;</P>
<P>MATLAB的版本是6.5.1
以上是我从书上刚查到的,具体怎么使用还不是很清楚,大家自己用help吧。</P>
发表于 2004-7-17 00:29:08 | 显示全部楼层
谢咯
发表于 2004-7-17 23:44:31 | 显示全部楼层
<b><EM><FONT style="BACKGROUND-COLOR: #5577aa" color=#f70909 size=5>duoxie duoxie</FONT></EM></b>
发表于 2004-7-18 20:53:04 | 显示全部楼层
<>我觉得matlab中的Jacobi函数求偏导更为方便!看一看 就知道啦!</P><>&gt;&gt; syms x y z
&gt;&gt; jacobian(x^2+y^2+z^2,[x,y,z])

ans =

[ 2*x, 2*y, 2*z]</P>
发表于 2004-7-18 21:16:26 | 显示全部楼层
<>有没有关于MATLAB编程方面(详细的介绍)的免费资料!</P>
发表于 2004-7-20 09:45:57 | 显示全部楼层
<>好东东</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-11-30 19:41 , Processed in 0.058960 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表