• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest May 6th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. 1;
2. clear;
3. clc;
4. function v=c(x)
5.   if(x==0)
6.     v=0;
7.   else
8.     v=(50+10*x)*x;
9.   endif
10. endfunction
11. function v=p(x)
12.   v=8*x;
13. endfunction
14. kmax=[0 10 12 8 5 6 2];
15. e=[2 7 1 2 6 1];
16. x=zeros(15,1);
17. kmin=[0 0 0 0 0 0 2];
18. x_opt=[0 0 0 0 0 0];
19. min=1000;
20. for i=1:6
21.   for k=kmin(i+1):kmax(i+1)
22.     if(((kmin(i)-k+e(i))>=0) && ((kmin(i)-k+e(i))<=5))
23.     x(k+1)=kmin(i)-k+e(i);
24.     xs(k+1)=p(kmin(i))+c(x(k+1));
25.   else
26.     xs(k+1)=500000;
27.   endif
28.   if(min>xs(k+1))
29.     min=xs(k+1);
30.     mink=k;
31.   endif
32.   x_opt(i)=kmin(i)-mink+e(i);
33.   kmin(i+1)=mink;
34.   if(i==1)
35.    w(i)=min;
36.   else
37.    w(i)=w(i-1)+min;
38.   endif
39. endfor
40. min=1000;
41. endfor
42. for i=7:-1:1
43.   x_opt_again=[0 x_opt];
44.   w_opt(i-length(i)+1)=p(kmin(i))+c(x_opt_again(i));
45. endfor
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top