helen66 435 اشتراک گذاری ارسال شده در 5 فروردین، ۱۳۹۴ با سلام و وقت بخیر چطور میتونم سرعت اجرای ی برنامه تو متلب رو بالا ببرم؟ با سپاس 2 نقل قول لینک به دیدگاه
ehsan_faal 561 اشتراک گذاری ارسال شده در 5 فروردین، ۱۳۹۴ سلام. 1-اجتناب از حلقه ها 2- استفاده از profiler 3-در صورت امکان استفاده از mex 4-گذاشتن کد رو این سایت و هم فکری با سایر دوستان 2 نقل قول لینک به دیدگاه
helen66 435 مالک اشتراک گذاری ارسال شده در 6 فروردین، ۱۳۹۴ با سلام و وقت بخیر ممنون از پاسخ مفیدتون...تعداد کدها زیاده اونها رو بصورت مجزا قرار میدم ممنون میشم کمکم کنید،کد نهایی espso هستش که سرعتش پایینه: function [PLOSS V]=foku(xx) countnum=0; BranchData = [ 1 2 1.00922 1.00470; 2 3 1.004930 1.002511; 3 4 0.003660 0.1864; 4 6 0.03811 0.1941; 4 5 0.03811 0.1941; 6 7 0.1872 0.6188; 7 8 0.7114 0.2351; 8 9 1.0300 0.7400; 9 10 1.0440 0.7400; 10 11 0.0966 0.0650; 11 12 0.0744 0.1238; 9 13 0.0680 1.1550; 13 14 0.0416 0.7129; 13 15 0.0910 0.5260; 15 16 0.0463 0.5450; 16 17 0.2890 1.7210; 17 18 0.7320 0.5740; 17 19 0.1640 0.1565; 19 20 0.5042 1.3554; 20 21 0.4095 0.4784; 21 22 0.7089 0.9373; 20 23 0.4512 0.3083; 23 24 0.8980 0.7091; 23 25 0.8960 0.7011; 25 26 0.2030 0.1034; 26 27 0.2842 0.1447; 27 28 0.0590 0.9337; 28 29 0.8042 0.7006; 25 30 0.5075 0.2585; 30 31 0.9744 0.9630; 31 32 0.3105 0.3619; 31 33 0.3410 0.5302; 33 34 0.3410 0.5302; ]; NodeData = [ 2 100.00 60.00; 3 90.00 40.00; 4 80.00 80.00; 5 60.00 30.00; 6 60.00 80.00; 7 80.00 80.00; 8 80.00 90.00; 9 60.00 20.00; 10 60.00 20.00; 11 45.00 80.00; 12 60.00 65.00; 13 60.00 65.00; 14 120.00 80.00; 15 60.00 60.00; 16 60.00 60.00; 17 60.00 60.00; 18 90.00 40.00; 19 90.00 40.00; 20 90.00 40.00; 21 90.00 40.00; 22 90.00 40.00; 23 90.00 50.00; 24 80.00 10.00; 25 80.00 10.00; 26 60.00 65.00; 27 60.00 65.00; 28 60.00 60.00; 29 80.00 70.00; 30 100.00 30.00; 31 150.00 70.00; 32 110.00 100.00; 33 60.00 40.00; 34 60.00 40.00; ]; UB = 12.66; SB = sum(xx) ; ZB = UB^2/SB; BranchData(:,[3,4]) = BranchData(:,[3,4]) / ZB; NodeData(:,[2,3]) = NodeData(:,[2,3]) / SB / 1800; NN = 34; A0 = zeros(NN); for n = 1:NN-1 A0(BranchData(n,1),BranchData(n,2)) = 1; end AssociatedMatrix=0; for n=2:NN-1 AssociatedMatrix(n,n)=1; temp=BranchData(n-1,1); AssociatedMatrix(n,1:n-1)=AssociatedMatrix(temp,1:n-1); end A0T = A0'; S = [0;-NodeData(:,2) - 1i*NodeData(:,3)]; ZL = [0;BranchData(:,3) + 1i*BranchData(:,4)]; V = ones(NN,1); V(1) = 1; IL(NN,1) = -conj(S(NN) / V(NN)); Delta = 1; TempV = V; while Delta > 1e-3 countnum=countnum+1; IN = conj(S ./ V); for n = 1:NN-1 IL(NN-n) = A0(NN-n,NN-n+1:end) * IL(NN-n+1:end) - IN(NN-n); end for n = 2:NN V(n) = A0T(n,1:n-1) * V(1:n-1) - ZL(n) * IL(n); end Delta = max(abs(V-TempV)); TempV = V; end Vangle(:,1)=abs(V); Vangle(:,2)=angle(V)/3.1415*180; for i=1:NN-1 st=BranchData(i,1); en=BranchData(i,2); Sij(i,1)=V(st)*conj((V(st)-V(en))/ZL(i+1)); Sji(i,1)=V(en)*conj((V(en)-V(st))/ZL(i+1)); end PLOSS=sum(real(Sij))*1000-(SB/1.2); end 1 نقل قول لینک به دیدگاه
helen66 435 مالک اشتراک گذاری ارسال شده در 6 فروردین، ۱۳۹۴ کد espso clc clear; close all; %% Problem Definition global NFE; CostFunction=@(Prate) cost222(Prate); % Cost Function nVar=24; % Number of Decision Variables VarSize=[1 nVar]; % Size of Decision Variables Matrix % Lower Bound of Variables VarMax=6 ; % Upper Bound of Variables PL=[1.7 1.5 1.3 1.32 1.4 1.52 1.6 1.9 2.1 2.25 2.4 2.5 2.55 2.56 2.59 2.55 ... 2.8 3.2 3.5 3.7 3.73 3.4 3 2.3]; VarMin=PL ; %% PSO Parameters MaxIt=300; % Maximum Number of Iterations nPop=30; % Population Size (Swarm Size) wmax=1; % Inertia Weight wmin=0.2; % Inertia Weight Damping Ratio c1=2; % Personal Learning Coefficient c2=2; % Global Learning Coefficient % Constriction Coefficients % phi1=2.05; % phi2=2.05; % phi=phi1+phi2; % chi=2/(phi-2+sqrt(phi^2-4*phi)); % w=chi; % Inertia Weight % wdamp=1; % Inertia Weight Damping Ratio % c1=chi*phi1; % Personal Learning Coefficient % c2=chi*phi2; % Global Learning Coefficient % Velocity Limits VelMax=0.1*(VarMax-VarMin); VelMin=-VelMax; %% Initialization empty_particle.Position=[]; empty_particle.Cost=[]; empty_particle.Velocity=[]; empty_particle.Best.Position=[]; empty_particle.Best.Cost=[]; particle=repmat(empty_particle,nPop,1); GlobalBest.Cost=inf; for i=1:nPop Prate=randsrc(1,1,[.001:.01:.2])*PL+PL; % Initialize Position particle(i).Position=Prate; % Initialize Velocity particle(i).Velocity=zeros(VarSize); % Evaluation particle(i).Cost=CostFunction(particle(i).Position); % Update Personal Best particle(i).Best.Position=particle(i).Position; particle(i).Best.Cost=particle(i).Cost; % Update Global Best if particle(i).Best.Cost<GlobalBest.Cost GlobalBest=particle(i).Best; end end disp('aaaa') BestCost=zeros(MaxIt,1); nfe=zeros(MaxIt,1); w=1; %% PSO Main Loop for it=1:MaxIt for i=1:nPop % Update Velocity particle(i).Velocity = w*particle(i).Velocity ... +c1*rand(VarSize).*(particle(i).Best.Position-particle(i).Position) ... +c2*rand(VarSize).*(GlobalBest.Position-particle(i).Position); % Apply Velocity Limits particle(i).Velocity = max(particle(i).Velocity,VelMin); particle(i).Velocity = min(particle(i).Velocity,VelMax); % Update Position particle(i).Position = particle(i).Position + particle(i).Velocity; % Velocity Mirror Effect % IsOutside=(particle(i).Position<VarMin | particle(i).Position>VarMax); % particle(i).Velocity(IsOutside)=-particle(i).Velocity(IsOutside); % % Apply Position Limits particle(i).Position = max(particle(i).Position,VarMin); particle(i).Position = min(particle(i).Position,VarMax); %for iv=1:24 % particle(iv).Position(iv)= PL(iv)+rand*1e2; %end % Evaluation particle(i).Cost = CostFunction(particle(i).Position); % Update Personal Best if particle(i).Cost<particle(i).Best.Cost; particle(i).Best.Position=particle(i).Position; particle(i).Best.Cost=particle(i).Cost; % Update Global Best if particle(i).Best.Cost<GlobalBest.Cost GlobalBest=particle(i).Best; end end end BestCost(it)=GlobalBest.Cost; disp(['Iteration ' num2str(it) ', Best Cost = ' num2str(BestCost(it))]); w=wmax-it*((wmax-wmin)/MaxIt); end %% Results cost1 = zzz(GlobalBest.Position ); figure; plot([1:300],BestCost,'LineWidth',2); xlabel('Iteration'); ylabel('Best Cost'); [PLOSS V]=foku(GlobalBest.Position); figure; plot([1:34],V,'-*'); xlabel('BUS'); ylabel('Voltage'); 1 نقل قول لینک به دیدگاه
helen66 435 مالک اشتراک گذاری ارسال شده در 6 فروردین، ۱۳۹۴ کد cos222 function cost1 = cost222(Prate ) %UNTITLED3 Summary of this function goes here % Detailed explanation goes here % daily travel distance beta1=0.1; beta2=0.2; alfa=10; t=1:24; a=readfis('gu1'); %Read a fuzzy inference system from a gu1 x=normrnd(9.97,2.2,24,1); %depend on arrival time y=normrnd(17.01,3.2,24,1); %depond on departure time d=evalfis([x y],a); %daily travel distance aer=[30,40,60]; %DIFFERENT AERS dr1=aer(randi([1,3],1)); landa=d./100; %percentage of mileage driven in all electrical... % mode if (landa.*d)>zeros(24,1),(landa.*d)<(0.8.*dr1); socinitial=(1-(landa.*d)./dr1)*100; elseif (landa*d)>=0.8*dr1; socinitial=0.2; end %BATTERY CAPACITY FOR DIFFERENT TYPES OF PHEV (kWh) h1=[7.8,9,11.4,13.8]; p1=h1(randi([1,4],1,1)); h2=[10.4,12,15.2,18.4]; p2=h2(randi([1,4],1,1)); h3=[15.6,18,22.8,27.6]; p3=h3(randi([1,4],1,1)); p=[p1 p2 p3]; eta=0.85+(0.9-0.85)*rand(1,24); % the charging efficiency factor c=p(randi(1,1,24)); %BATTERY CAPACITY ereq=((1-socinitial).*c')./eta'; %The energy required to fulfill the battery %Smart Pricing Policy psys=ereq'./t; %load demand of the system at time slot pavg=ereq./24; %the average load demand of the system % disp(rt); % kd1=eye(1,100); k=[-1,0,1]; kd=k(randi([1,3],1,24 )); %charging strategy %the rated charging power of the dth PHEV for pp=1:24 rt(pp)=beta1+(beta2*(alfa.^((psys(pp)-pavg(pp))./pavg(pp)))); end for t=1:24 coschg(t)=abs( kd(t)*Prate(t).*rt(t)); %charging cost end % disp(coschg) %Battery Degradation Cost cl=240; lc=5000; % etadis=0.8; cb=300; % Edis=300; DOD=0.8; h1=[7.8,9,11.4,13.8,10.4,12,15.2,18.4,15.6,18,22.8,27.6]; Eb=h1(randi([1,12],1,24)); % kd1=eye(1,100); k=[-1,0,1]; kd=k(randi([1,3],1,24 )); Dd=zeros(1,24); Dd(kd==-1)=1; %discharging state of PHEVs for t=1:24 Edis(t)=Dd(t).*Prate(t); costbat(t)=abs((((cb*Eb(t))+cl)/((lc*DOD)*Eb(t)))*Edis(t));%discharge energy by PHEVs end %Battery Degradation Cost % disp(costbat); reg=.4928; %regulation service price at time slot % kd1=eye(1,100); k=[-1,0,1]; kd=k(randi([1,3],1,24 )); %charging strategy %the rated charging power of the dth PHEV Id=zeros(1,24); %idle state of PHEVs Id(kd==0)=1; %the frequency regulation capacity of the system Earnreg=0; for t=1:24 pr(t)=Id(t).*Prate(t); Earnreg=Earnreg+abs(pr(t).*reg); %revenue earned by regulation service end qq=sum(coschg); qqq=sum(costbat); qqqq=Earnreg; % Earnreg1=Earnreg.*eye(1,100); cost1=sum(coschg)+sum(costbat)-Earnreg; end 1 نقل قول لینک به دیدگاه
helen66 435 مالک اشتراک گذاری ارسال شده در 18 فروردین، ۱۳۹۴ با سلام دوستان کسی نتونست مشکل بالا رو حل کنه؟؟؟ نقل قول لینک به دیدگاه
hfml 1545 اشتراک گذاری ارسال شده در 18 فروردین، ۱۳۹۴ سلام متاسفانه وقت ندارم کدتون رو بخونم ولی به طور کلی همون جور که دوستمون گفتن، اگه بتونین به جای حلقه، از بردار یا ماتریس استفاده کنید خوبه. تو اینترنت جستجو کنید: VECTORIZATION IN MATLAB این لینک رو هم نگاه کنید. البته خودم امتحان نکردم این روشو ولی به نظر خوب میاد. از پردازش موازی و gpu هم میتونید استفاده کنید ولی کدتون رو باید درست بنویسید گویا تا بشه از اینا استفاده کرد. مسئله تون هم باید قابلیت موازی سازی داشته باشه. 3 نقل قول لینک به دیدگاه
asadiiii 0 اشتراک گذاری ارسال شده در 6 فروردین، ۱۴۰۰ سلام بزرگوار خوبی شما میگم میتونین یک سوال رو راجب متلب بهم کمک کنین عکس سوال رو پایین بارگذاری کردم Last name:asadzadeh نقل قول لینک به دیدگاه
ارسال های توصیه شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .