﻿ 数学建模10 - 四元数矩阵计算(Quaternion Matrix Computations) - 专，学者，数值代数，微分方程数值解

### 数学建模10

function u=DecisFun(k,x)

if x == 1 ,u = [2;3];

elseif x == 2,u = [4;5;6];

elseif x == 3,u = [5;6;7];

elseif (x==4)||(x==5), u = [8;9];

elseif (x==6)||(x==7),u = [9;10];

elseif x==8,u = [11,12];

elseif (x==9)||(x==10),u = [12;13];

elseif (x==11)||(x==12)||(x==13),u = [14;15];

elseif (x==14)||(x==15),u = 16;

elseif x==16,u =16;

end

function V=ObjFun(k,x,u)

tt=[5;3;1;3;6;8;7;6;6;8;3;5;3;3;8;4;2;2;1;2;3;3;3;5;5;2;6;6;4;3];

tmp = [x == 1&& u == 2,x == 1&& u == 3,x == 2&& u == 4,x == 2&& u == 5,...

x == 2&& u == 6,x == 3&& u == 5,x == 3&& u == 6,x == 3&& u == 7,...

x == 4&& u == 8,x == 4&& u == 9,x == 5&& u == 8,x == 5&& u == 9,...

x == 6&& u == 9,x == 6&& u == 10,x == 7&& u == 9,x == 7&& u == 10,...

x == 8&& u == 11,x == 8&& u == 12,x == 9&& u == 11,x == 9&& u == 12,...

x == 10&& u == 12,x == 10&& u == 13,x == 11&& u == 14,x == 11&& u == 15,...

x == 12&& u == 14,x == 12&& u == 15,x == 13&& u == 14,x == 13&& u == 15,...

x == 14&& u == 16,x == 15&& u == 16];

V = tmp*tt;

function s_next=TransFun(k,x,u)

s_next=u;

clear all

clc

x=nan*ones(4,7);

x(1,1)=1;

x(1:2,2) = [2;3];

x(1:4,3)=(4:7)';

x(1:3,4)=(8:10)';

x(1:3,5)=(11:13)';

x(1:2,6)=[14;15];

x(1,7)=16;

[p_opt,fval]=dynprog(x,@DecisFun,@ObjFun,@TransFun);

 月份（k） 1 2 3 4 需求量（DK） 2 3 2 4

Eg2

function u=DecisFun(k,x)

m=6;

d = [ 2 3 2 4 ];

if k == 4

u = d(k) - x;

else

u = max (0,d(k)-x):m;

end

function V=ObjFun(k,x,u)

d = [ 2 3 2 4 ];

if u == 0

V = 0.5 * (x + u -d(k));

else

if u>6

V = 10^6;

else

V = 3 + u +0.5*(x + u -d(k));

end

end

function s_next=TransFun(k,x,u)

d = [ 2 3 2 4 ];

s_next = x + u - d(k);

clear all

clc

x1 = 0:4;

s=nan*ones(5,1);

s(1) = 0;

x = [s x1' x1' x1'];

[p_opt,fval]=dynprog(x,@DecisFun,@ObjFun,@TransFun);

Eg3

function u=DecisFun(k,x)

d =100* [ 6 7 5 12];

if k == 4

u = d(k) - x;

else

u = max (0,d(k)-x):1200;

end

function V=ObjFun(k,x,u)

V = x+ 0.005*u^2;

function s_next=TransFun(k,x,u)

d = [ 600 700 500 1200];

s_next = x + u - d(k);

clear all

clc

x1 =100*(0:4);

s = nan*ones(5,1);

s(1)=0;

x = [s x1' x1' x1'];

[p_opt,fval]=dynprog(x,@DecisFun,@ObjFun,@TransFun);

Eg4

function u=DecisFun(k,x)

u = 0 : x;

function V=ObjFun(k,x,u)

if u>900

V = 0;

else

V =8*u  + 5*(x-u);

V=-V;

end

function s_next=TransFun(k,x,u)

a = 0.7;

b = 0.9;

s_next =(a - b)*u + b*x;

clear all

clc

x1 = (500:999);

s=nan*ones(500,1);

s(1) = 1000;

x = [s x1' x1' x1' x1'];

[p_opt,fval]=dynprog(x,@DecisFun,@ObjFun,@TransFun);