Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
consider preallocatiing for speed

Subject: consider preallocatiing for speed

From: chan young jung

Date: 25 Sep, 2010 14:53:05

Message: 1 of 2

1) file object function

function f= objet_cost34(x)

f=((100*x(1))-(5.81*x(1))+(50*x(1)))/20+ ((450*x(2))-(26.14*x(2))+(86*x(2)))/20+((500*x(3))+(200*x(3)))/20 ;

2) file
% 풍력발전량
pw(1)= 2.412 * x(1) ;
pw(2)= 0.512 * x(1) ;
pw(3)= 1.321 * x(1) ;
pw(4)= 1.079 * x(1) ;
pw(5)= 3.538 * x(1) ;
pw(6)= 3.538 * x(1) ;
pw(7)= 3.609 * x(1) ;
pw(8)= 4.621 * x(1) ;
pw(9)= 4.055 * x(1) ;
pw(10)= 4.706 * x(1) ;
pw(11)= 4.212 * x(1) ;
pw(12)= 3.828 * x(1) ;
pw(13)= 5.055 * x(1) ;
pw(14)= 3.538 * x(1) ;
pw(15)= 3.263 * x(1) ;
pw(16)= 2.524 * x(1) ;
pw(17)= 2.638 * x(1) ;
pw(18)= 3.330 * x(1) ;
pw(19)= 3.681 * x(1) ;
pw(20)= 2.940 * x(1) ;
pw(21)= 2.468 * x(1) ;
pw(22)= 2.000 * x(1) ;
pw(23)= 1.905 * x(1) ;
pw(24)= 1.680 * x(1) ;

% 태양광 발전량
ps(1)= 0.000 * x(2) ;
ps(2)= 0.000 * x(2) ;
ps(3)= 0.000 * x(2) ;
ps(4)= 0.000 * x(2) ;
ps(5)= 0.000 * x(2) ;
ps(6)= 0.000 * x(2) ;
ps(7)= 0.000 * x(2) ;
ps(8)= 0.000 * x(2) ;
ps(9)= 0.025 * x(2) ;
ps(10)= 0.046 * x(2) ;
ps(11)= 0.060 * x(2) ;
ps(12)= 0.067 * x(2) ;
ps(13)= 0.066 * x(2) ;
ps(14)= 0.058 * x(2) ;
ps(15)= 0.043 * x(2) ;
ps(16)= 0.022 * x(2) ;
ps(17)= 0.000 * x(2) ;
ps(18)= 0.000 * x(2) ;
ps(19)= 0.000 * x(2) ;
ps(20)= 0.000 * x(2) ;
ps(21)= 0.000 * x(2) ;
ps(22)= 0.000 * x(2) ;
ps(23)= 0.000 * x(2) ;
ps(24)= 0.000 * x(2) ;

% 전력수요
pd(1)= 2716.920 ;
pd(2)= 2706.120 ;
pd(3)= 2746.800 ;
pd(4)= 2672.280 ;
pd(5)= 2696.400 ;
pd(6)= 2872.800 ;
pd(7)= 2708.640 ;
pd(8)= 2586.240 ;
pd(9)= 2556.720 ;
pd(10)= 2522.160 ;
pd(11)= 2493.000 ;
pd(12)= 2565.000 ;
pd(13)= 2561.760 ;
pd(14)= 2631.240 ;
pd(15)= 2729.520 ;
pd(16)= 2825.280 ;
pd(17)= 2961.720 ;
pd(18)= 3181.320 ;
pd(19)= 3155.040 ;
pd(20)= 3122.280 ;
pd(21)= 3058.200 ;
pd(22)= 3155.760 ;
pd(23)= 3097.440 ;
pd(24)= 3003.120 ;

% pbmin
pbmin=3;


% soc
soc(1)= 0;
soc(2)= soc(1);
soc(3)= soc(2);
soc(4)= soc(3);
soc(5)= soc(4);
soc(6)= soc(5);
soc(7)= soc(6);
soc(8)= soc(7);
soc(9)= soc(8);
soc(10)=soc(9);
soc(11)=soc(10);
soc(12)=soc(11);
soc(13)=soc(12);
soc(14)=soc(13);
soc(15)=soc(14);
soc(16)=soc(15);
soc(17)=soc(16);
soc(18)=soc(17);
soc(19)=soc(18);
soc(20)=soc(19);
soc(21)=soc(20);
soc(22)=soc(21);
soc(23)=soc(22);
soc(24)=soc(23);


a=zeros(1,24);
b=zeros(1,24);
c=zeros(1,24);
d=zeros(1,24);
e=zeros(1,24);
u=zeros(1,24);
pb=zeros(1,24);
h=zeros(1,24);
j=zeros(1,24);


for i= 1:24;
    a(i)= pw(i)+ps(i); % 총발전량
    b(i)= a(i)-pd(i); % 잉여전력량
    c(i)= soc(i)+(b(i)*0.82); % 베터리 충전량
    d(i)= soc(i)-((pd(i)-a(i))/0.82) ; % 베터리 방전량
    
    if a(i)> pd(i)
        u(i)=0;
        pb(i)=c(i); % 베터리 충전
    
    else
        u(i)=1;
        pb(i)=d(i); % 베터리 방전
    end
    
     e(i)=(pbmin-c(i)-b(i))*u(i); % EENS
     h(i)=-a(i)-pb(i)+(1-(e(i)/67325.76))*pd(i); % 제약조건
    j(i)=a(i)+pb(i)-(a(i)+pb(i)-pd(i))-pd(i); % 제약조건




 
    

cin= [pbmin-c(i); % pbmin<= pbsoc<= x(3)
         c(i)-x(3); % pbsoc= soc(t-1)+(pw(t)+ps(t)-pd(t))*0.82
         h(i);
         j(i);
        
          ];
    
    ceq=[];
end



my program is well operation
but consider preallocating for speed
and i'm input
a=zeros(1,24);
b=zeros(1,24);
c=zeros(1,24);
d=zeros(1,24);
e=zeros(1,24);
u=zeros(1,24);
pb=zeros(1,24);
h=zeros(1,24);
j=zeros(1,24);

x(1)=400:1:10000
x(2)=40:1:4000
x(3)= 0:1:40

above
 Is zeros's Automatic Matrix control for calcaulation ??

Subject: consider preallocatiing for speed

From: Innocent

Date: 26 Sep, 2010 11:20:11

Message: 2 of 2

"chan young jung" <chanchan1982@nate.com> wrote in message <i7l2ch$r9l$1@fred.mathworks.com>...
> 1) file object function
>
> function f= objet_cost34(x)
>
> f=((100*x(1))-(5.81*x(1))+(50*x(1)))/20+ ((450*x(2))-(26.14*x(2))+(86*x(2)))/20+((500*x(3))+(200*x(3)))/20 ;
>
> 2) file
> % 풍력발전량
> pw(1)= 2.412 * x(1) ;
> pw(2)= 0.512 * x(1) ;
> pw(3)= 1.321 * x(1) ;
> pw(4)= 1.079 * x(1) ;
> pw(5)= 3.538 * x(1) ;
> pw(6)= 3.538 * x(1) ;
> pw(7)= 3.609 * x(1) ;
> pw(8)= 4.621 * x(1) ;
> pw(9)= 4.055 * x(1) ;
> pw(10)= 4.706 * x(1) ;
> pw(11)= 4.212 * x(1) ;
> pw(12)= 3.828 * x(1) ;
> pw(13)= 5.055 * x(1) ;
> pw(14)= 3.538 * x(1) ;
> pw(15)= 3.263 * x(1) ;
> pw(16)= 2.524 * x(1) ;
> pw(17)= 2.638 * x(1) ;
> pw(18)= 3.330 * x(1) ;
> pw(19)= 3.681 * x(1) ;
> pw(20)= 2.940 * x(1) ;
> pw(21)= 2.468 * x(1) ;
> pw(22)= 2.000 * x(1) ;
> pw(23)= 1.905 * x(1) ;
> pw(24)= 1.680 * x(1) ;
>
> % 태양광 발전량
> ps(1)= 0.000 * x(2) ;
> ps(2)= 0.000 * x(2) ;
> ps(3)= 0.000 * x(2) ;
> ps(4)= 0.000 * x(2) ;
> ps(5)= 0.000 * x(2) ;
> ps(6)= 0.000 * x(2) ;
> ps(7)= 0.000 * x(2) ;
> ps(8)= 0.000 * x(2) ;
> ps(9)= 0.025 * x(2) ;
> ps(10)= 0.046 * x(2) ;
> ps(11)= 0.060 * x(2) ;
> ps(12)= 0.067 * x(2) ;
> ps(13)= 0.066 * x(2) ;
> ps(14)= 0.058 * x(2) ;
> ps(15)= 0.043 * x(2) ;
> ps(16)= 0.022 * x(2) ;
> ps(17)= 0.000 * x(2) ;
> ps(18)= 0.000 * x(2) ;
> ps(19)= 0.000 * x(2) ;
> ps(20)= 0.000 * x(2) ;
> ps(21)= 0.000 * x(2) ;
> ps(22)= 0.000 * x(2) ;
> ps(23)= 0.000 * x(2) ;
> ps(24)= 0.000 * x(2) ;
>
> % 전력수요
> pd(1)= 2716.920 ;
> pd(2)= 2706.120 ;
> pd(3)= 2746.800 ;
> pd(4)= 2672.280 ;
> pd(5)= 2696.400 ;
> pd(6)= 2872.800 ;
> pd(7)= 2708.640 ;
> pd(8)= 2586.240 ;
> pd(9)= 2556.720 ;
> pd(10)= 2522.160 ;
> pd(11)= 2493.000 ;
> pd(12)= 2565.000 ;
> pd(13)= 2561.760 ;
> pd(14)= 2631.240 ;
> pd(15)= 2729.520 ;
> pd(16)= 2825.280 ;
> pd(17)= 2961.720 ;
> pd(18)= 3181.320 ;
> pd(19)= 3155.040 ;
> pd(20)= 3122.280 ;
> pd(21)= 3058.200 ;
> pd(22)= 3155.760 ;
> pd(23)= 3097.440 ;
> pd(24)= 3003.120 ;
>
> % pbmin
> pbmin=3;
>
>
> % soc
> soc(1)= 0;
> soc(2)= soc(1);
> soc(3)= soc(2);
> soc(4)= soc(3);
> soc(5)= soc(4);
> soc(6)= soc(5);
> soc(7)= soc(6);
> soc(8)= soc(7);
> soc(9)= soc(8);
> soc(10)=soc(9);
> soc(11)=soc(10);
> soc(12)=soc(11);
> soc(13)=soc(12);
> soc(14)=soc(13);
> soc(15)=soc(14);
> soc(16)=soc(15);
> soc(17)=soc(16);
> soc(18)=soc(17);
> soc(19)=soc(18);
> soc(20)=soc(19);
> soc(21)=soc(20);
> soc(22)=soc(21);
> soc(23)=soc(22);
> soc(24)=soc(23);
>
>
> a=zeros(1,24);
> b=zeros(1,24);
> c=zeros(1,24);
> d=zeros(1,24);
> e=zeros(1,24);
> u=zeros(1,24);
> pb=zeros(1,24);
> h=zeros(1,24);
> j=zeros(1,24);
>
>
> for i= 1:24;
> a(i)= pw(i)+ps(i); % 총발전량
> b(i)= a(i)-pd(i); % 잉여전력량
> c(i)= soc(i)+(b(i)*0.82); % 베터리 충전량
> d(i)= soc(i)-((pd(i)-a(i))/0.82) ; % 베터리 방전량
>
> if a(i)> pd(i)
> u(i)=0;
> pb(i)=c(i); % 베터리 충전
>
> else
> u(i)=1;
> pb(i)=d(i); % 베터리 방전
> end
>
> e(i)=(pbmin-c(i)-b(i))*u(i); % EENS
> h(i)=-a(i)-pb(i)+(1-(e(i)/67325.76))*pd(i); % 제약조건
> j(i)=a(i)+pb(i)-(a(i)+pb(i)-pd(i))-pd(i); % 제약조건
>
>
>
>
>
>
>
> cin= [pbmin-c(i); % pbmin<= pbsoc<= x(3)
> c(i)-x(3); % pbsoc= soc(t-1)+(pw(t)+ps(t)-pd(t))*0.82
> h(i);
> j(i);
>
> ];
>
> ceq=[];
> end
>
>
>
> my program is well operation
> but consider preallocating for speed
> and i'm input
> a=zeros(1,24);
> b=zeros(1,24);
> c=zeros(1,24);
> d=zeros(1,24);
> e=zeros(1,24);
> u=zeros(1,24);
> pb=zeros(1,24);
> h=zeros(1,24);
> j=zeros(1,24);
>
> x(1)=400:1:10000
> x(2)=40:1:4000
> x(3)= 0:1:40
>
> above
> Is zeros's Automatic Matrix control for calcaulation ??

I dont understand full your function, but i think you need to pre-allocate the pw, ps, x(1),x(2),x(3) as well, you mighty consider giving different varaiables names to x(2), x(3) as well. see if that help to speed up your program.

Innocent

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us