求教:如何用Matlab编写这个动态规划的程序

求教:如何用Matlab编写这个动态规划的程序,第1张

建立唤猜数学模型设xi=1表和稿型示Ai被选中,xi=0表示Ai没被选中。则数学模型是:max 1500x1+2000x2+1300x3+2300x4+2800x5s.t. x1+x2=1 x4+x5=1 x1+x4<=1 x2-x5=0 xi=0或1,i=1,2,3,4,5 2.编程求敬顷解matlab程序:f=[-1500-2000-1300-2300-2800]A=[10010]b=1Aeq=[11000000110100-1]beq=[110]x=bintprog(f,A,b,Aeq,beq)解出来是:x=01101也就是说运送A2,A3,A5

%%(1)题此春首

I=imread('abc.jpg'森数)

II=rgb2gray(I)

imshow(II)

for i=1:size(II,1)

for j=1:size(II,2)

if (0<=II(i,j) &&II(i,j)<=50)

III(i,j)=2

elseif (50<II(i,j) &&II(i,j)<=100)

III(i,j)=8

elseif (100<II(i,j) &&II(i,j)<=150)

III(i,j)=16

elseif (150<II(i,j) &&II(i,j)<=200)

III(i,j)=64

elseif(200<II(i,j) &&II(i,j)<=250)

III(i,j)=128

end

end

end

figure

imshow(III)

%%(2)题

x=linspace(0,2*pi,500)

for i=1:length(x)

if (x(i)<=pi)

y1(i)=1

else

y1(i)=0

end

if (x(i)<=pi)

y2(i)=x(i)/pi

else

y2(i)=(2*pi-x(i))/pi

end

y3(i)=sin(x(i))

end

figureplot(x,y1)

figureplot(x,y2)

figureplot(x,y3)

figure

subplot(1,3,1)plot(x,y1)

subplot(1,3,2)plot(x,y2)

subplot(1,3,3)plot(x,y3)

figureplot(x,y1,x,y2,x,y3)legend('方波'森陪,'三角波','正弦')

%%(3)题

eps=0.001

xl=3fl=xl^3-xl^2-6*xl-7 %不支持函数就直接写。

xr=4fr=xr^3-xr^2-6*xr-7

while (1)

xm=(xl+xr)/2fm=xm^3-xm^2-6*xm-7

if (abs(fm)<eps)

break

elseif (fm*fl<0)

xr=xmfr=fm

else

xl=xmfl=fm

end

end

x=xm

f(x)

50分...重谢桐绝友宏圆 = =||

function [ans1 ans2 ans3]=fff_sha(C)

[m n]=size(C)

c1=0.2

c2=0.5

c3=0.8

for i=1:m

for j=1:n

aaa=C(i,j)

if (aaa>=0)&&(aaa<=c1)

ans1(i,j)=0ans2(i,j)=0ans3(i,j)=1

continue

end

if (aaa>=c1)&&(aaa<局槐=c2)

ans1(i,j)=0ans2(i,j)=(c2-aaa)/(c2-c1)ans3(i,j)=(aaa-c1)/(c2-c1)

continue

end

if (aaa>=c2)&&(aaa<=c3)

ans1(i,j)=(c3-aaa)/(c3-c2)ans2(i,j)=(aaa-c2)/(c3-c2)ans3(i,j)=0

continue

end

if (aaa>=c3)&&(aaa<=1)

ans1(i,j)=1ans2(i,j)=0ans3(i,j)=0

continue

end

end

end


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12480983.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存