Month: October 2024
How to Encrypt the web.config’s Identity Section in IIS
How to Encrypt the web.config’s Identity Section in IIS
Securing Sensitive Information in Your Web Application
In today’s digital age, ensuring the security and privacy of sensitive information is paramount. One crucial file in ASP.NET applications, the web.config, often contains sensitive data, including connection strings, passwords, appsettings and identity sections. Encrypting these sections can significantly enhance your application’s security.
This blog will guide you through the process of encrypting the web.config’s identity section in Internet Information Services (IIS).
Why Encrypt the web.config’s Identity Section?
The <identity> section in the web.config file is used to specify the identity under which the ASP.NET application should run. This is especially important if the application needs to run under a specific user account for security reasons, such as accessing restricted network resources.
Before encryption :
Here’s an example of what this section might look like:
<configuration>
<system.web>
<identity impersonate=”true” userName=”domainusername” password=”password” />
</system.web>
</configuration>
Using the <identity> section allows you to run your application with specific permissions, which can be crucial for accessing network resources or other restricted operations.
You might not want to store plain text credentials in your web.config, so consider encrypting this section to enhance security.
Before diving into the technicalities, it’s essential to understand why encrypting the web.config’s identity section is necessary. The `web.config` file stores configuration settings for your ASP.NET web application. If left unencrypted, sensitive information in this file can be easily accessed by unauthorized users, leading to potential security breaches. Encrypting the identity section ensures that this critical information is protected and only accessible by authorized processes.
Prerequisites
To follow this guide, you’ll need:
Administrative access to the IIS server.
Basic understanding of IIS and ASP.NET configuration files.
Windows Server or any other system running IIS.
Steps to Encrypt the Identity Section
Step 1: Open Command Prompt as Administrator
To begin, open the Command Prompt with administrative privileges. You can do this by searching for “cmd” in the Start menu, right-clicking on “Command Prompt,” and selecting “Run as administrator.”
Step 2: Navigate to the .NET Framework Directory
Depending on the version of the .NET Framework you are using, navigate to its directory. For example, if you are using .NET Framework 4.0, you would navigate to:
cd C:WindowsMicrosoft.NETFrameworkv4.0.30319
cd C:WindowsMicrosoft.NETFramework64v4.0.30319
Step 3: Use aspnet_regiis to Encrypt the Identity Section
The `aspnet_regiis.exe` tool is used to encrypt and decrypt sections of the `web.config` file. To encrypt the identity section, use the following command:
ASPNET_REGIIS -pef “system.web/identity” -app “/YourApplicationName” -site “YourSiteName”
Replace `YourApplicationName` with the virtual directory name of your application and `YourSiteName` with the name of your site in IIS.
Step 4: Verify the Encryption
After executing the command, navigate to your `web.config` file and verify that the identity section is now encrypted. The encrypted section will look similar to this:
Issues
This will help encrypt the identity section, however when you try to access the application, you will end up getting below error :
For resolving this you need to make sure to add :
<system.webServer>
<validation validateIntegratedModeConfiguration=”false” />
</system.webServer>
Once you add this the issue will be resolved.
Post encryption
Decrypting the Identity Section
In some scenarios, you may need to decrypt the identity section for troubleshooting or other purposes. The `aspnet_regiis` tool also allows you to decrypt sections:
Best Practices for Encrypting Configuration Sections
Encrypting the identity section is a critical step in securing your application, but there are additional best practices you should follow:
Regularly Update Encryption Keys: Ensure that encryption keys are updated regularly to prevent potential security vulnerabilities.
Limit Access to the web.config File: Only authorized personnel should have access to the `web.config` file to reduce the risk of unauthorized modifications.
Monitor and Audit: Implement monitoring and auditing mechanisms to track any changes made to the `web.config` file.
Conclusion
Encrypting the `web.config`’s identity section in IIS is a straightforward yet powerful way to enhance the security of your ASP.NET applications.
By following the steps outlined in this blog, you can protect sensitive information and ensure that it is only accessible by authorized processes. Always remember to follow best practices and continuously monitor your application’s security to mitigate potential risks.
Microsoft Tech Community – Latest Blogs –Read More
SharePoint Week: Seven virtual webinars (October 14-18, 2024) | ESPC Learning Hub
“Any fool can know. The (Share) Point is to understand.’
– Albert Einstein (with light (following brand guidelines) modification)
Don’t be foolish. Don’t miss out on this upcoming opportunity to go from knowing to understanding.
We’re excited to share what the ESPC team has planned for you ahead of ESPC24 later this year in Stockholm, Sweden. Mark your calendars, October 14-18 is SharePoint Week, and it’s shark free (we think). It’s a week-long event packed with free, expert-led online sessions designed to boost your knowledge and skills in all things SharePoint.
What: SharePoint Week
Register today for one or all seven virtual webinars.
When & where: October 14th – 18th, 2024 | Online [one to two sessions per day; see all below]
Twitter & hashtag: @ESPC_Community | #TechCon365
Cost: Free.
SharePoint Week webinars
Join Microsoft product makers and MVPs – top community contributors – as they share insights, best practices, and innovative solutions to help you thrive in your SharePoint journey. Whether you’re looking to streamline collaboration, improve data management, or unlock new capabilities, this is the event for you.
“Creating custom Copilots for SharePoint Online with Microsoft Copilot Studio” presented by Paolo Pialorsi, MVP | Monday, Oct. 14, 11:00 CEST
“Creating contracts with SharePoint Premium’s Content Assembly” presented by Sari Soinoja, MVP | Monday, Oct. 14, 16:00 CEST
“Building Your Copilot Muscle: Practical Examples” presented by Zoe Wilson, MVP | Tuesday, Oct. 15, 11:00 CEST
“Developers! Learn how to use the SharePoint Framework to customize and extend SharePoint” presented by Andrew Connell, MVP | Tuesday, Oct. 15, 16:00 CEST
“The Path to an Engaged and Vibrant Community” presented by Merethe Stave, MVP | Wednesday, Oct. 16, 16:00 CEST
“Information Protection: SharePoint” presented by Aman Kumar, Microsoft | Thursday, Oct. 17, 11:00 CEST
“New Capabilities with SharePoint Pages” presented by Marijn Somers, MVP | Friday, Oct. 18, 16:00 CEST
Sharing is caring – and we thank Paolo, Sari, Zoe, Andrew, Merethe, Aman, Marijn, and the whole ESPC team for caring, and the sharing that is to come during SharePoint Week.
Share SharePoint Week with your peers, partners, and customers. And join in.
And make a plan to attend ESPC24 later this year in Stockholm, Sweden:
What: ESPC24 to learn more.
Where: Stockholmsmässan Exhibition Centre | | Mässvägen 1, 125 80 Stockholm, Sweden
When: December 2-5, 2024
Use the code ESPC24COMM to get a €150 discount on all tickets | Book now
Cheers, Mark “We’re gonna need a bigger server farm” Kashman
Microsoft Tech Community – Latest Blogs –Read More
Windows 11, version 24H2 security baseline
Microsoft is pleased to announce the release of the security baseline package for Windows 11, version 24H2!
Please download the content from the Microsoft Security Compliance Toolkit, test the recommended configurations, and customize / implement as appropriate.
This release includes several changes to further assist in the security of enterprise customers, including additional protections to LAN Manager, Kerberos, User Account Control, Microsoft Defender Antivirus updates, and more.
Mark of the Web
You may have seen previous discussions on the Mark of the Web (MotW) within our baselines at some point. A new setting has been added and configured, located at Windows ComponentsFile ExplorerDo not apply the Mark of the Web tag to files copied from insecure sources. This new setting will be enforced with a value of Disabled. This adds the MotW when copying a file from a network share (in the Internet Zone) into the local file system. If necessary, Zone Mapping can be used to map any file shares that are deemed trusted into the Trusted/Intranet Zones.
LAN Manager
For each release, we conduct a complete review of settings as part of our security baseline. Based on the latest review, we are updating our recommended settings for LAN Manager (Lanman) including Lanman Server and Lanman Workstation.
NetworkLanman Server
Audit client does not support encryption – set to a value of Enabled
Audit client does not support signing – set to a value of Enabled
Audit insecure guest logon – set to a value of Enabled
Enable authentication rate limiter – set to a value of Enabled
Enable remote mailslots – set to a value of Disabled
Mandate the maximum version of SMB – set to a value of Enabled: SMB 3.1.1
Mandate the minimum version of SMB – set to a value of Enabled: SMB 3.0.0
Set authentication rate limiter delay (milliseconds) – set to a value of Enabled: 2000
NetworkLanman Workstation
Audit insecure guest logon – set to a value of Enabled
Audit server does not support encryption – set to a value of Enabled
Audit server does not support signing – set to a value of Enabled
Enable remote mailslots – set to a value of Disabled
Mandate the maximum version of SMB – set to a value of Enabled: SMB 3.1.1
Mandate the minimum version of SMB – set to a value of Enabled: SMB 3.0.0
Require Encryption – set a value of Disabled
Configure hash algorithms for certificate logon
A new setting, located at SystemKDC and SystemKerberos, has been added for smart card crypto agility. This setting lets users configure the hash algorithm to be used in certificate-based smart card (PKINIT) authentication of Kerberos. With this configuration, customers have the option to prevent SHA-1 from being used. The security baseline recommends support for SHA-256, SHA-384, and SHA-512, but does not recommend support for SHA-1. It’s important to note these settings are useful only if both the client and KDC (Windows Server 2025) are configured this way in the environment.
Sudo command
Located at SystemConfigure the behavior of the sudo command, this setting allows the customization of how the sudo command operates. Sudo for Windows can be used as a potential escalation of privilege vector when enabled in certain configurations. The baseline configures this setting to a value of Disabled, which disables sudo for Windows.
Microsoft Defender Antivirus
Microsoft Defender Antivirus (MDAV) plays a critical part in our security story. We are constantly making improvements to the product and have included six new settings in this release.
Windows ComponentsMicrosoft Defender AntivirusControl whether exclusions are visible to local users – set to a value of Enabled
Windows ComponentsMicrosoft Defender AntivirusFeaturesEnable EDR in block mode – set to a value of Enabled
Windows ComponentsMicrosoft Defender AntivirusNetwork Inspection SystemConvert warn verdict to block – set to a value of Enabled
Windows ComponentsMicrosoft Defender AntivirusReal-time ProtectionConfigure real-time protection and Security Intelligence Updates during OOBE – set to a value of Enabled
Windows ComponentsMicrosoft Defender AntivirusReportingConfigure whether to report Dynamic Signature dropped events – set to a value of Enabled
Windows ComponentsMicrosoft Defender AntivirusScanScan excluded files and directories during quick scans – set to a value of Enabled: 1
User Account Control
Two settings affecting User Account Control have been added.
Enhanced Privilege Protection Mode helps provide an additional layer of protection against malware and other threats by isolating sensitive data and processes. Located in the security template at Security OptionsBehavior of the elevation prompt for administrators in Enhanced Privilege Protection Mode, the baseline configures this setting to Prompt for credentials on secure desktop.
A second policy controls whether enhanced privilege protection is applied to admin approval mode elevations. Located in the security template at Security OptionsConfigure type of Admin Approval Mode, we recommend setting this to a value of Admin Approval Mode with enhanced privilege protection.
Additional items worth considering
The following settings should be evaluated based on your environment.
Delegated Managed Service Account (dMSA)
We have introduced a new policy called Enable delegated Managed Service Account (dMSA) Logons which is located at SystemKerberos. This controls dMSA logons for the machine. If you enable this policy setting, dMSA logons will be supported by the Kerberos client. Please review the prerequisites before adjusting the policy setting.
By default, dMSA is disabled because the Domain Controller (DC) must also be upgraded to Windows Server 2025 for the feature to function properly. If the DC is running a version earlier than Server 2025, the necessary schema updates for dMSA will not be present.
If your DC has been upgraded to Windows Server 2025, we suggest enabling this policy on both the client and DC sides. When enabled, you may need to specify realms, i.e., which domains or parts of the directory can authenticate and access the dMSA account. A child domain on an older server version can still interact with the accounts while maintaining security boundaries. It allows for a smoother transition and coexistence of features across a mixed-version environment. For example, if you have a primary domain called corp.contoso.com running on Windows Server 2025 and an older child domain called legacy.corp.contoso.com running on an older version of Windows Server (e.g., Windows Server 2022), you may specify the realm as legacy.corp.contoso.com. To learn more, see Setting up delegated Managed Service Accounts (dMSA) in Windows Server 2025.
Windows Protected Print
Windows Protected Print (WPP) is the new, modern and more secure print for Windows built from the ground up with security in mind. WPP blocks 3rd party drivers and hardens the entire print stack from attacks. WPP is designed to work with Mopria certified printers. While not yet configured in the security baseline, we recommend you consider the setting PrintersConfigure Windows protected print as later versions of the baselines will look to enable this very important feature. You can learn more about the security benefits in our blog post.
Microsoft Defender Antivirus
There are several Microsoft Defender Antivirus (MDAV) settings we recommend you consider.
Windows ComponentsMicrosoft Defender AntivirusReal-time ProtectionConfigure performance mode status is beneficial for developers who utilize Dev Drive on Windows 11. More information on Dev Drive can be found here.
The following two settings are specific to VDI environments.
Windows ComponentsMicrosoft Defender AntivirusNetwork Inspection SystemTurn on asynchronous inspection helps to ensure there is no slowdown in the detection process.
Windows ComponentsMicrosoft Defender AntivirusSecurity Intelligence UpdatesConfigure security intelligence updates according to the scheduler for VDI clients controls the flow of the SIUs.
Other changes
We have decided to remove SystemGroup PolicyConfigure registry policy processing from the security baseline after feedback from our support engineers on the numerous issues that were being traced back to it.
Several minor discrepancies between the documentation and group policies were noted since the last release. These should all be addressed going forward.
Please let us know your thoughts by commenting on this post or through the Security Baseline Community.
Microsoft Tech Community – Latest Blogs –Read More
error regarding wgdx and rgdx
Hi, please someone tell me regarding integration of MATLAB code with GAMS, i want to implement DCOPF. I receive this error in MATLAB:Error using wgdx:Amount of full format .val data exceeds number of UELs. Please try to resolve it, is my wgdx and rgdx functions working?
This is my MATLAB code:
clear all
close all
clc
%inputs
mpc=load (‘grid_data_24bus.mat’);
profile_L=mpc.WD(:,3);
profile_gen_rand=[1.0057;1.027;0.98;0.967;0.9837;0.971;1.001;1.04063;1.0129;0.961;0.989;0.9554;1.000129;0.9937;1.0497;1.0316;0.9986;1.03944;0.963;0.989;1.0427;1.041749;1.0214;1.0118];
n_time = 24; % time intervals
DeltaT = 24/n_time; % granularity
n_bus = size(mpc.BusData,1); % Number of buses
n_brnc = size(mpc.branches,1); % Number of branches
n_gen = size(mpc.Gen,1); % num of generators
slack = 13; % slack choice
VS = 1; % default value for slack voltage
V_up=1.1; % Voltage limits
V_lo=0.9; % Voltage limits
% Time profiles
mpc.BusData = repmat (mpc.BusData, [1,1,n_time]);
mpc.Gen = repmat (mpc.Gen, [1,1,n_time]);
for t=1:n_time
mpc.BusData(:,2,t)=profile_L(t).*mpc.BusData(:,2,t);% column 2 have Pd
for g=1:size(mpc.Gen,1)
mpc.Gen(g,3:4,t)=profile_gen_rand(t).*( mpc.Gen(g,3:4,t));%pmax and pmin
end
end
mpc_pre=mpc; %save mpcstruct
%%% ESS allocation
SOC_max = 100; % battery size [MWh]
SOC_0 = 0.2*SOC_max/mpc.Sbase; % initial SoC [per unit]
eta_c = 0.95; % charge efficiency
eta_d = 0.9; % discharge efficiency
VOLL = 10000; % Value of Loss of Load
VWC = 50; % Value of loss of wind ($/MWh)
% Define Wind Capacity and Generation Profiles for Specific Buses
% Define Wind Capacity and Generation Profiles for Specific Buses
Wcap = zeros(n_bus, 1); % Wind capacity array for all buses
Wcap(8) = 200; % Bus 8: 200 MW
Wcap(19) = 150; % Bus 19: 150 MW
Wcap(21) = 100; % Bus 21: 100 MW
% Wind data over 24 hours (from ‘w’ column)
wind_profile = mpc.WD(:, 2); % 24-hour wind profile
% Wind Generation Matrix (Buses x Time)
wind_gen = Wcap * wind_profile’; % Corrected dimensions
% sending data to GAMS
% Time index for GAMS file
TT=cell(1,n_time);
for tt=1:n_time
TT{tt}=[‘t’,num2str(tt)];
end
y.name=’t’;
y.type=’set’;
y.uels=TT;
% Nodes
bus = linspace(1,n_bus,n_bus)’;
Bus.name=’bus’;
Bus.type=’set’;
Bus.uels=num2cell(bus)’;
% Slack bus
Slack.name=’slack’;
Slack.type=’set’;
Slack.val=slack;
Slack.uels=Bus.uels;
% Generators
GG=cell(1,n_gen);
for gg=1:n_gen
GG{gg}=[‘g’,num2str(gg)];
end
gen.name=’Gen’;
gen.type=’set’;
gen.uels=GG;
% S_base
S_base.name=’sbase’;
S_base.type=’parameter’;
S_base.val=mpc.Sbase;
S_base.form=’full’;
S_base.dim=0;
% VOLL
VoLL.name=’VOLL’;
VoLL.type=’parameter’;
VoLL.val=VOLL;
VoLL.form=’full’;
VoLL.dim=0;
% Value wind curtailment
Vwc.name=’VWC’;
Vwc.type=’parameter’;
Vwc.val=VWC;
Vwc.form=’full’;
Vwc.dim=0;
% Charge efficiency []
Eta_c.name=’eta_c’;
Eta_c.type=’parameter’;
Eta_c.val=eta_c;
Eta_c.form=’full’;
Eta_c.dim=0;
% Discharge efficiency []
Eta_d.name=’eta_d’;
Eta_d.type=’parameter’;
Eta_d.val=eta_d;
Eta_d.form=’full’;
Eta_d.dim=0;
% Maximum battery SoC [MWh]
socmax.name=’SOCmax’;
socmax.type=’parameter’;
socmax.val=SOC_max;
socmax.form=’full’;
socmax.dim=0;
% Initial battery SoC [0-1]
socini.name=’SOC0′;
socini.type=’parameter’;
socini.val=SOC_0;
socini.form=’full’;
socini.dim=0;
% Wind and load power profiles []
%WD(t,*) wind-demand daily variation patterns: ‘w’ wind ‘d’ demand
wd.name=’WD’;
wd.type=’parameter’;
wd.val=mpc.WD(:,2:3);
wd.form=’full’; %missing indices are zero
wd.dim=2;
wd.uels={TT,{‘w’,’d’}};
% Branches data
%branches(bus,node,*) ‘r(pu)’ ‘x(pu)’ ‘b(pu)’ ‘limit(MVA)’
branches = [];
for ii=1:size(branches,1)
branches=vertcat(branches, zeros(4,4));
branches((ii-1)*4+1:ii*4,:)=….
[ branches(ii,1) branches(ii,2) 1 branches(ii,3); … from to ‘r’ value
branches(ii,1) branches(ii,2) 2 branches(ii,4); … from to ‘x’ value
branches(ii,1) branches(ii,2) 3 branches(ii,5); … from to ‘b’ value
branches(ii,1) branches(ii,2) 4 branches(ii,6) ]; … from to ‘limit’ value
end
Branches.name=’branches’;
Branches.type=’parameter’;
Branches.val=mpc.Branches;
Branches.form=’sparse’; %missing indices are zero
Branches.uels={Bus.uels, Bus.uels, {‘r’,’x’,’b’,’limit’}};
Branches.dim=3;
% Gen bus location
gb.name=’GB’;
gb.type=’set’;
gb.val=mpc.Gen(:,1:2); %GB(Gen,bus) generating buses
gb.val(:,1) = 1:n_gen;
gb.form=’sparse’;
gb.dim=2;
gb.uels={gen.uels,{1:24}}; % Covering all 24 buses in the system
% Gen data
GenData=[mpc.Gen(:,5)’; mpc.Gen(:,4)’; mpc.Gen(:,3)’; mpc.Gen(:,8)’; mpc.Gen(:,9)’]’; %GenData GD(Gen,*) ‘b’ ‘pmin’ ‘pmax’ ‘RU’ ‘RD’ -> ‘b’ t.c. Gen_cost = a*Pg^2 + b*Pg + c
Gen_Data.name=’GD’;
Gen_Data.type=’parameter’;
Gen_Data.val=GenData;
Gen_Data.form=’full’;
Gen_Data.dim=2;
Gen_Data.uels={GG,{‘b’,’pmin’,’pmax’,’RU’,’RD’}};
% Define the WCap parameter
WCap.name = ‘Wcap’; % Parameter name
WCap.type = ‘parameter’; % Define it as a parameter
WCap.val = Wcap; % Assign wind capacity values from Wcap
WCap.form = ‘full’; % Missing indices are assumed zero
WCap.dim = 1; % One-dimensional parameter (indexed by buses)
WCap.uels = {Bus.uels}; % Link the parameter to the bus indices
% Bus data
Bus_Data.name=’BusData’;
Bus_Data.type=’parameter’;
Bus_Data.val=[mpc.BusData(:,1) ones(size(mpc.BusData,1),1) mpc.BusData(:,2) mpc.BusData(:,1) 2*ones(size(mpc.BusData,1),1) mpc.BusData(:,3)];
Bus_Data.val=reshape(Bus_Data.val’, [size(Bus_Data.val’,1)/2,size(Bus_Data.val’,2)*2]);
Bus_Data.val=Bus_Data.val’;
Bus_Data.form=’sparse’;
Bus_Data.dim=2;
Bus_Data.uels={Bus.uels,{‘Pd’,’Qd’}};
%% GAMS calculation
GAMSfolder=[];
wgdxName=’dcopf_bess’;
% write gdx file as input for GAMS model
wgdx(wgdxName,y,gen,Bus,Slack,S_base,VoLL,Vwc,Eta_c,Eta_d,socmax,socini,wd,gb,Gen_Data,WCap,Bus_Data,Branches);
% gdxInfo DC_OPF %to print and check gdx input file
% run Gams file
gams([ ‘dcopf_bess’ ‘ lo=2’ ]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% read the gdx output file from GAMS
solGDX=[GAMSfolder ‘dcopf_bess_Solution.gdx’];
rs = struct(‘name’,’returnStat’,’compress’,’true’);
stats = rgdx(solGDX,rs);
gdxInfo DC_OPF_Solution %print gdx results
%matout file contains:
%OF, Pij(bus,node,t), delta(bus,t),
%Pg(Gen,t), lsh (bus,t), Pw(bus,t), pwc(bus,t),
%SOC(bus,t), Pd(bus,t), Pc(bus,t),NESS(bus);
% print of the stats of the GAMS run
disp([‘Best possible: ‘,num2str(stats.val(1,2))]);
disp([‘Objective: ‘,num2str(stats.val(2,2))]);
disp([‘Optimality gap: ‘,num2str((stats.val(2,2)-stats.val(1,2))/(stats.val(1,2))*100),’ %’]);
disp([‘Time: ‘,num2str(stats.val(3,2)), ‘ s’]);
disp([‘Model status: ‘,num2str(stats.val(4,2)), ‘(1: optimal, 8: integer solution model found)’]);
disp(‘Done!’)
disp(‘ ‘)
%% Results
% reading of the results related to charge power
P_c = struct(‘name’,’Pc’,’form’,’sparse’,’compress’,’true’);
sP_c=rgdx(solGDX,P_c);
P_c = zeros(n_bus,n_time);
for ijk=1:length(sP_c.val(:,3))
P_c(sP_c.val(ijk,1),sP_c.val(ijk,2)) = sP_c.val(ijk,3);
end
% reading of the results related to discharge power
P_d = struct(‘name’,’Pd’,’form’,’sparse’,’compress’,’true’);
sP_d=rgdx(solGDX,P_d);
P_d = zeros(n_bus,n_time);
for ijk=1:length(sP_d.val(:,3))
P_d(sP_d.val(ijk,1),sP_d.val(ijk,2)) = sP_d.val(ijk,3);
end
% reading of the results related to the State of Charge
SoC_batt=struct(‘name’,’SOC’,’form’,’full’,’compress’,’true’);
sSoC_B=rgdx(solGDX,SoC_batt);
SoC = zeros(n_bus,n_time);
SoC = sSoC_B.val;
% reading of the results related to number of batteries
NESS=struct(‘name’,’NESS’,’form’,’full’,’compress’,’true’);
sNESS=rgdx(solGDX,NESS);
idx = str2double(sNESS.uels{1});
N_ESS = zeros(n_bus,1);
N_ESS(idx) = sNESS.val;
figure;
stairs(N_ESS)
xlabel(‘bus number’)
ylabel(‘Number of ESS’)
ylim([0 max(N_ESS)+0.2])
% reading of the results related to generators
P_gen=struct(‘name’,’Pg’,’form’,’full’,’compress’,’true’);
sP_gen=rgdx(solGDX,P_gen);
P_gen = zeros(n_gen,n_time);
P_gen = sP_gen.val;
% wind curtailment result
P_cut=struct(‘name’,’pwc’,’form’,’full’,’compress’,’true’);
sP_Cut=rgdx(solGDX,P_cut);
P_cur = zeros(n_bus,n_time);
P_cur = sP_Cut.val;
% load shedding result
P_sh=struct(‘name’,’lsh’,’form’,’full’,’compress’,’true’);
sP_sh=rgdx(solGDX,P_sh);
Psh = zeros(n_bus,n_time);
Psh = sP_sh.val;
figure;
plot(P_cur)
hold on
plot(Psh)
hold off
xlabel(‘time [h]’)
ylabel(‘Wind curtailment and load shedding’)
legend(‘Curtailment’,’Load shedding’)
% Pij flows result
P_ij = struct(‘name’,’Pij’,’form’,’sparse’,’compress’,’true’);
sP_ij=rgdx(solGDX,P_ij);
P_ij = zeros(n_bus, n_bus, n_time); % If Pij is bus-to-bus over time
for ijk=1:length(sP_ij.val(:,3))
P_ij(sP_ij.val(ijk,1), sP_ij.val(ijk,2), sP_ij.val(ijk,3)) = sP_ij.val(ijk,4);
end
% Plotting power flow between bus i and bus j over time
i = 1; % Sending bus
j = 2; % Receiving bus
figure;
stairs(1:n_time, squeeze(P_ij(i,j,:)));
xlabel(‘Time’);
ylabel([‘Power flow from bus ‘, num2str(i), ‘ to bus ‘, num2str(j)]);
title(‘Power Flow between Buses over Time’);
This is integration with GAMS to see its output:
$set matout1 "’dcopf_bess_Solution.gdx’,returnStat,t,OF,Pd,Pc,SOC,Pij,Pg,lsh,pwc"
Sets
t time
DeltaT granularity
bus buses
Gen generators
GB(Gen,bus) generators’ bus location
slack(bus) slack bus;
alias(bus,node);
scalar
sbase base power
V_up upper voltage limit
V_lo lower voltage limit
eta_c charge efficiency
eta_d discharge efficiency
VWC Value of Wind curtailment
VOLL Value of Loss of Load;
parameters
SOCmax battery size [MWh]
SOC0 initial SoC [per unit]
GD(Gen,*) Generator data
branches(bus,node,*) r(pu) x(pu) b(pu) limit(MVA)
WD(t,*) Wind-demand daily variation patterns: ‘w’ wind ‘d’ demand
Wcap(bus) Wind capacities
BusData(bus,*) Demands of each bus in MW;
$gdxin "C:UsersuserDesktopmatpower7.1datadcopf_bess.gdx"
$load t Gen sbase bus slack VOLL VWC eta_c eta_d SOCmax SOC0 WD GD GB WCap BusData branches
$gdxin
Scalars Nmax;
branches(bus,node,’x’)$(branches(bus,node,’x’)=0)=branches(node,bus,’x’);
branches(bus,node,’limit’)$(branches(bus,node,’limit’)=0)=branches(node,bus,’limit’);
branches(bus,node,’bij’)$(conex(bus,node))=1/branches(node,bus,’x’);
Parameter conex(bus,node) Bus connectivity matrix;
conex(bus,node)$(conex(node,bus))=1;
conex(bus,node)$(branches(bus,node,’limit’) and branches(node,bus,’limit’)) =1;
Variables OF, Pij(bus,node,t),Pg(Gen,t),delta(bus,t), pw(bus,t),lsh(bus,t),SOC(bus,t),pwc(bus,t),Pd(bus,t),Pc(bus,t);
Integer variable NESS(bus);
Equations objfnc, balance,const1,const2,const3,const4,constESS,constESS2,constESS3(bus,t),constESS4(bus,t),constESS5(bus,t),constESS6(bus,t);
balance(bus,t)..sum(node$(conex(node,bus)),Pij(bus,node,t))=e=sum(Gen$(GB(Gen,bus)),Pg(Gen,t))+lsh(bus,t)$busdata(bus,’Pd’)+pw(bus,t)$Wcap(bus)-Pc(bus,t)$SOCmax(bus)+Pd(bus,t)$SOCmax(bus)-WD(t,’d’)*busdata(bus,’Pd’)/sbase;
const1(bus,node,t)$conex(bus,node)..Pij(bus,node,t)=e=branches(bus,node,’bij’)*(delta(bus,t)-delta(node,t));
const2(Gen,t)..Pg(Gen,t+1)-Pg(Gen,t)=l=Gendata(Gen,’RU’)/sbase;
const3(Gen,t)..Pg(Gen,t-1)-Pg(Gen,t)=l=Gendata(Gen,’RD’)/sbase;
const4(bus,t)$Wcap(bus)..pwc(bus,t)=e=WD(t,’w’)*Wcap(bus)/sbase-pw(bus,t);
constESS(bus,t)$SOCmax(bus)..SOC(bus,t)=e=(0.2*NESS(bus)*SOCmax/sbase)$(ord(t)=1)+SOC(bus,t-1)$(ord (t)>1)+(Pc(bus,t)$SOCmax(bus)*eta_c)-(Pd(bus,t)$SOCmax(bus)/eta_d);
constESS2(bus,t) .. SOC(bus,t)=l=NESS(bus)*SOCmax/sbase ;
*P_max charge
constESS3(bus,t) .. Pc(bus,t)=l=0.2*NESS(bus)*SOCmax/sbase ;
*P_max discharge
constESS4(bus,t) .. Pd(bus,t)=l=0.2*NESS(bus)*SOCmax/sbase ;
*limit on total ESSs
constESS5 .. sum(bus,NESS(bus))=l=Nmax;
*final SoC imposition (SoC0=0.2*SOCmax)
constESS6(bus) .. SOC(bus,’t24′)=e=0.2*NESS(bus)*SOCmax/sbase ;
objfnc..OF=e=sum((bus,Gen,t)$GB(Gen,bus),Pg(Gen,t)*Gendata(Gen,’b’)*sbase)+sum((bus,t),VOLL*lsh(bus,t)*sbase$(busdata(bus,’Pd’))+VOLW*pwc(bus,t)*Sbase$(Wcap(bus)));
Model load_flow/all/;
Pij.lo(bus,node,t)$(conex(bus,node))=-1*branches(bus,node,’limit’)/sbase;
Pij.up(bus,node,t)$(conex(bus,node))=1*branches(bus,node,’limit’)/sbase;
Pg.lo(Gen,t)=GD(Gen,’Pmin’)/sbase;
Pg.up(Gen,t)=GD(Gen,’Pmax’)/sbase;
delta.lo(bus,t)=-pi/2;
delta.up(bus,t)=pi/2;
delta.fx(slack,t)=0;
Pc.lo(bus,t)=0;
Pd.lo(bus,t)=0;
SOC.lo(bus,t)=0;
NESS.up(bus)=5;
Nmax=110;
pw.lo(bus,t)=0;
pw.up(bus,t)=WD(t,’w’)*Wcap(bus)/Sbase;
pwc.lo(bus,t)=0;
pwc.up(bus,t)=WD(t,’w’)*Wcap(bus)/Sbase;
lsh.lo(bus,t)=0;
lsh.up(bus,t)=WD(t,’d’)*busdata(bus,’Pd’)/Sbase;
Solve load_flow using MIP minimizing OF;
set stat /bestpossible,objective,tgams,tsolver,modelstat,solvestat/;
parameter returnStat(stat);
returnStat(‘bestpossible’) = loadflow.objest;
returnStat(‘objective’) = loadflow.objval;
returnStat(‘tsolver’) = loadflow.resusd;
returnStat(‘modelstat’) = loadflow.modelstat;
returnStat(‘solvestat’) = loadflow.solvestat;
execute_unload %matout1%
display Pg.l,Pij.l,delta.l, pwc.l,lsh.l,Pc.l,Pd.l;Hi, please someone tell me regarding integration of MATLAB code with GAMS, i want to implement DCOPF. I receive this error in MATLAB:Error using wgdx:Amount of full format .val data exceeds number of UELs. Please try to resolve it, is my wgdx and rgdx functions working?
This is my MATLAB code:
clear all
close all
clc
%inputs
mpc=load (‘grid_data_24bus.mat’);
profile_L=mpc.WD(:,3);
profile_gen_rand=[1.0057;1.027;0.98;0.967;0.9837;0.971;1.001;1.04063;1.0129;0.961;0.989;0.9554;1.000129;0.9937;1.0497;1.0316;0.9986;1.03944;0.963;0.989;1.0427;1.041749;1.0214;1.0118];
n_time = 24; % time intervals
DeltaT = 24/n_time; % granularity
n_bus = size(mpc.BusData,1); % Number of buses
n_brnc = size(mpc.branches,1); % Number of branches
n_gen = size(mpc.Gen,1); % num of generators
slack = 13; % slack choice
VS = 1; % default value for slack voltage
V_up=1.1; % Voltage limits
V_lo=0.9; % Voltage limits
% Time profiles
mpc.BusData = repmat (mpc.BusData, [1,1,n_time]);
mpc.Gen = repmat (mpc.Gen, [1,1,n_time]);
for t=1:n_time
mpc.BusData(:,2,t)=profile_L(t).*mpc.BusData(:,2,t);% column 2 have Pd
for g=1:size(mpc.Gen,1)
mpc.Gen(g,3:4,t)=profile_gen_rand(t).*( mpc.Gen(g,3:4,t));%pmax and pmin
end
end
mpc_pre=mpc; %save mpcstruct
%%% ESS allocation
SOC_max = 100; % battery size [MWh]
SOC_0 = 0.2*SOC_max/mpc.Sbase; % initial SoC [per unit]
eta_c = 0.95; % charge efficiency
eta_d = 0.9; % discharge efficiency
VOLL = 10000; % Value of Loss of Load
VWC = 50; % Value of loss of wind ($/MWh)
% Define Wind Capacity and Generation Profiles for Specific Buses
% Define Wind Capacity and Generation Profiles for Specific Buses
Wcap = zeros(n_bus, 1); % Wind capacity array for all buses
Wcap(8) = 200; % Bus 8: 200 MW
Wcap(19) = 150; % Bus 19: 150 MW
Wcap(21) = 100; % Bus 21: 100 MW
% Wind data over 24 hours (from ‘w’ column)
wind_profile = mpc.WD(:, 2); % 24-hour wind profile
% Wind Generation Matrix (Buses x Time)
wind_gen = Wcap * wind_profile’; % Corrected dimensions
% sending data to GAMS
% Time index for GAMS file
TT=cell(1,n_time);
for tt=1:n_time
TT{tt}=[‘t’,num2str(tt)];
end
y.name=’t’;
y.type=’set’;
y.uels=TT;
% Nodes
bus = linspace(1,n_bus,n_bus)’;
Bus.name=’bus’;
Bus.type=’set’;
Bus.uels=num2cell(bus)’;
% Slack bus
Slack.name=’slack’;
Slack.type=’set’;
Slack.val=slack;
Slack.uels=Bus.uels;
% Generators
GG=cell(1,n_gen);
for gg=1:n_gen
GG{gg}=[‘g’,num2str(gg)];
end
gen.name=’Gen’;
gen.type=’set’;
gen.uels=GG;
% S_base
S_base.name=’sbase’;
S_base.type=’parameter’;
S_base.val=mpc.Sbase;
S_base.form=’full’;
S_base.dim=0;
% VOLL
VoLL.name=’VOLL’;
VoLL.type=’parameter’;
VoLL.val=VOLL;
VoLL.form=’full’;
VoLL.dim=0;
% Value wind curtailment
Vwc.name=’VWC’;
Vwc.type=’parameter’;
Vwc.val=VWC;
Vwc.form=’full’;
Vwc.dim=0;
% Charge efficiency []
Eta_c.name=’eta_c’;
Eta_c.type=’parameter’;
Eta_c.val=eta_c;
Eta_c.form=’full’;
Eta_c.dim=0;
% Discharge efficiency []
Eta_d.name=’eta_d’;
Eta_d.type=’parameter’;
Eta_d.val=eta_d;
Eta_d.form=’full’;
Eta_d.dim=0;
% Maximum battery SoC [MWh]
socmax.name=’SOCmax’;
socmax.type=’parameter’;
socmax.val=SOC_max;
socmax.form=’full’;
socmax.dim=0;
% Initial battery SoC [0-1]
socini.name=’SOC0′;
socini.type=’parameter’;
socini.val=SOC_0;
socini.form=’full’;
socini.dim=0;
% Wind and load power profiles []
%WD(t,*) wind-demand daily variation patterns: ‘w’ wind ‘d’ demand
wd.name=’WD’;
wd.type=’parameter’;
wd.val=mpc.WD(:,2:3);
wd.form=’full’; %missing indices are zero
wd.dim=2;
wd.uels={TT,{‘w’,’d’}};
% Branches data
%branches(bus,node,*) ‘r(pu)’ ‘x(pu)’ ‘b(pu)’ ‘limit(MVA)’
branches = [];
for ii=1:size(branches,1)
branches=vertcat(branches, zeros(4,4));
branches((ii-1)*4+1:ii*4,:)=….
[ branches(ii,1) branches(ii,2) 1 branches(ii,3); … from to ‘r’ value
branches(ii,1) branches(ii,2) 2 branches(ii,4); … from to ‘x’ value
branches(ii,1) branches(ii,2) 3 branches(ii,5); … from to ‘b’ value
branches(ii,1) branches(ii,2) 4 branches(ii,6) ]; … from to ‘limit’ value
end
Branches.name=’branches’;
Branches.type=’parameter’;
Branches.val=mpc.Branches;
Branches.form=’sparse’; %missing indices are zero
Branches.uels={Bus.uels, Bus.uels, {‘r’,’x’,’b’,’limit’}};
Branches.dim=3;
% Gen bus location
gb.name=’GB’;
gb.type=’set’;
gb.val=mpc.Gen(:,1:2); %GB(Gen,bus) generating buses
gb.val(:,1) = 1:n_gen;
gb.form=’sparse’;
gb.dim=2;
gb.uels={gen.uels,{1:24}}; % Covering all 24 buses in the system
% Gen data
GenData=[mpc.Gen(:,5)’; mpc.Gen(:,4)’; mpc.Gen(:,3)’; mpc.Gen(:,8)’; mpc.Gen(:,9)’]’; %GenData GD(Gen,*) ‘b’ ‘pmin’ ‘pmax’ ‘RU’ ‘RD’ -> ‘b’ t.c. Gen_cost = a*Pg^2 + b*Pg + c
Gen_Data.name=’GD’;
Gen_Data.type=’parameter’;
Gen_Data.val=GenData;
Gen_Data.form=’full’;
Gen_Data.dim=2;
Gen_Data.uels={GG,{‘b’,’pmin’,’pmax’,’RU’,’RD’}};
% Define the WCap parameter
WCap.name = ‘Wcap’; % Parameter name
WCap.type = ‘parameter’; % Define it as a parameter
WCap.val = Wcap; % Assign wind capacity values from Wcap
WCap.form = ‘full’; % Missing indices are assumed zero
WCap.dim = 1; % One-dimensional parameter (indexed by buses)
WCap.uels = {Bus.uels}; % Link the parameter to the bus indices
% Bus data
Bus_Data.name=’BusData’;
Bus_Data.type=’parameter’;
Bus_Data.val=[mpc.BusData(:,1) ones(size(mpc.BusData,1),1) mpc.BusData(:,2) mpc.BusData(:,1) 2*ones(size(mpc.BusData,1),1) mpc.BusData(:,3)];
Bus_Data.val=reshape(Bus_Data.val’, [size(Bus_Data.val’,1)/2,size(Bus_Data.val’,2)*2]);
Bus_Data.val=Bus_Data.val’;
Bus_Data.form=’sparse’;
Bus_Data.dim=2;
Bus_Data.uels={Bus.uels,{‘Pd’,’Qd’}};
%% GAMS calculation
GAMSfolder=[];
wgdxName=’dcopf_bess’;
% write gdx file as input for GAMS model
wgdx(wgdxName,y,gen,Bus,Slack,S_base,VoLL,Vwc,Eta_c,Eta_d,socmax,socini,wd,gb,Gen_Data,WCap,Bus_Data,Branches);
% gdxInfo DC_OPF %to print and check gdx input file
% run Gams file
gams([ ‘dcopf_bess’ ‘ lo=2’ ]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% read the gdx output file from GAMS
solGDX=[GAMSfolder ‘dcopf_bess_Solution.gdx’];
rs = struct(‘name’,’returnStat’,’compress’,’true’);
stats = rgdx(solGDX,rs);
gdxInfo DC_OPF_Solution %print gdx results
%matout file contains:
%OF, Pij(bus,node,t), delta(bus,t),
%Pg(Gen,t), lsh (bus,t), Pw(bus,t), pwc(bus,t),
%SOC(bus,t), Pd(bus,t), Pc(bus,t),NESS(bus);
% print of the stats of the GAMS run
disp([‘Best possible: ‘,num2str(stats.val(1,2))]);
disp([‘Objective: ‘,num2str(stats.val(2,2))]);
disp([‘Optimality gap: ‘,num2str((stats.val(2,2)-stats.val(1,2))/(stats.val(1,2))*100),’ %’]);
disp([‘Time: ‘,num2str(stats.val(3,2)), ‘ s’]);
disp([‘Model status: ‘,num2str(stats.val(4,2)), ‘(1: optimal, 8: integer solution model found)’]);
disp(‘Done!’)
disp(‘ ‘)
%% Results
% reading of the results related to charge power
P_c = struct(‘name’,’Pc’,’form’,’sparse’,’compress’,’true’);
sP_c=rgdx(solGDX,P_c);
P_c = zeros(n_bus,n_time);
for ijk=1:length(sP_c.val(:,3))
P_c(sP_c.val(ijk,1),sP_c.val(ijk,2)) = sP_c.val(ijk,3);
end
% reading of the results related to discharge power
P_d = struct(‘name’,’Pd’,’form’,’sparse’,’compress’,’true’);
sP_d=rgdx(solGDX,P_d);
P_d = zeros(n_bus,n_time);
for ijk=1:length(sP_d.val(:,3))
P_d(sP_d.val(ijk,1),sP_d.val(ijk,2)) = sP_d.val(ijk,3);
end
% reading of the results related to the State of Charge
SoC_batt=struct(‘name’,’SOC’,’form’,’full’,’compress’,’true’);
sSoC_B=rgdx(solGDX,SoC_batt);
SoC = zeros(n_bus,n_time);
SoC = sSoC_B.val;
% reading of the results related to number of batteries
NESS=struct(‘name’,’NESS’,’form’,’full’,’compress’,’true’);
sNESS=rgdx(solGDX,NESS);
idx = str2double(sNESS.uels{1});
N_ESS = zeros(n_bus,1);
N_ESS(idx) = sNESS.val;
figure;
stairs(N_ESS)
xlabel(‘bus number’)
ylabel(‘Number of ESS’)
ylim([0 max(N_ESS)+0.2])
% reading of the results related to generators
P_gen=struct(‘name’,’Pg’,’form’,’full’,’compress’,’true’);
sP_gen=rgdx(solGDX,P_gen);
P_gen = zeros(n_gen,n_time);
P_gen = sP_gen.val;
% wind curtailment result
P_cut=struct(‘name’,’pwc’,’form’,’full’,’compress’,’true’);
sP_Cut=rgdx(solGDX,P_cut);
P_cur = zeros(n_bus,n_time);
P_cur = sP_Cut.val;
% load shedding result
P_sh=struct(‘name’,’lsh’,’form’,’full’,’compress’,’true’);
sP_sh=rgdx(solGDX,P_sh);
Psh = zeros(n_bus,n_time);
Psh = sP_sh.val;
figure;
plot(P_cur)
hold on
plot(Psh)
hold off
xlabel(‘time [h]’)
ylabel(‘Wind curtailment and load shedding’)
legend(‘Curtailment’,’Load shedding’)
% Pij flows result
P_ij = struct(‘name’,’Pij’,’form’,’sparse’,’compress’,’true’);
sP_ij=rgdx(solGDX,P_ij);
P_ij = zeros(n_bus, n_bus, n_time); % If Pij is bus-to-bus over time
for ijk=1:length(sP_ij.val(:,3))
P_ij(sP_ij.val(ijk,1), sP_ij.val(ijk,2), sP_ij.val(ijk,3)) = sP_ij.val(ijk,4);
end
% Plotting power flow between bus i and bus j over time
i = 1; % Sending bus
j = 2; % Receiving bus
figure;
stairs(1:n_time, squeeze(P_ij(i,j,:)));
xlabel(‘Time’);
ylabel([‘Power flow from bus ‘, num2str(i), ‘ to bus ‘, num2str(j)]);
title(‘Power Flow between Buses over Time’);
This is integration with GAMS to see its output:
$set matout1 "’dcopf_bess_Solution.gdx’,returnStat,t,OF,Pd,Pc,SOC,Pij,Pg,lsh,pwc"
Sets
t time
DeltaT granularity
bus buses
Gen generators
GB(Gen,bus) generators’ bus location
slack(bus) slack bus;
alias(bus,node);
scalar
sbase base power
V_up upper voltage limit
V_lo lower voltage limit
eta_c charge efficiency
eta_d discharge efficiency
VWC Value of Wind curtailment
VOLL Value of Loss of Load;
parameters
SOCmax battery size [MWh]
SOC0 initial SoC [per unit]
GD(Gen,*) Generator data
branches(bus,node,*) r(pu) x(pu) b(pu) limit(MVA)
WD(t,*) Wind-demand daily variation patterns: ‘w’ wind ‘d’ demand
Wcap(bus) Wind capacities
BusData(bus,*) Demands of each bus in MW;
$gdxin "C:UsersuserDesktopmatpower7.1datadcopf_bess.gdx"
$load t Gen sbase bus slack VOLL VWC eta_c eta_d SOCmax SOC0 WD GD GB WCap BusData branches
$gdxin
Scalars Nmax;
branches(bus,node,’x’)$(branches(bus,node,’x’)=0)=branches(node,bus,’x’);
branches(bus,node,’limit’)$(branches(bus,node,’limit’)=0)=branches(node,bus,’limit’);
branches(bus,node,’bij’)$(conex(bus,node))=1/branches(node,bus,’x’);
Parameter conex(bus,node) Bus connectivity matrix;
conex(bus,node)$(conex(node,bus))=1;
conex(bus,node)$(branches(bus,node,’limit’) and branches(node,bus,’limit’)) =1;
Variables OF, Pij(bus,node,t),Pg(Gen,t),delta(bus,t), pw(bus,t),lsh(bus,t),SOC(bus,t),pwc(bus,t),Pd(bus,t),Pc(bus,t);
Integer variable NESS(bus);
Equations objfnc, balance,const1,const2,const3,const4,constESS,constESS2,constESS3(bus,t),constESS4(bus,t),constESS5(bus,t),constESS6(bus,t);
balance(bus,t)..sum(node$(conex(node,bus)),Pij(bus,node,t))=e=sum(Gen$(GB(Gen,bus)),Pg(Gen,t))+lsh(bus,t)$busdata(bus,’Pd’)+pw(bus,t)$Wcap(bus)-Pc(bus,t)$SOCmax(bus)+Pd(bus,t)$SOCmax(bus)-WD(t,’d’)*busdata(bus,’Pd’)/sbase;
const1(bus,node,t)$conex(bus,node)..Pij(bus,node,t)=e=branches(bus,node,’bij’)*(delta(bus,t)-delta(node,t));
const2(Gen,t)..Pg(Gen,t+1)-Pg(Gen,t)=l=Gendata(Gen,’RU’)/sbase;
const3(Gen,t)..Pg(Gen,t-1)-Pg(Gen,t)=l=Gendata(Gen,’RD’)/sbase;
const4(bus,t)$Wcap(bus)..pwc(bus,t)=e=WD(t,’w’)*Wcap(bus)/sbase-pw(bus,t);
constESS(bus,t)$SOCmax(bus)..SOC(bus,t)=e=(0.2*NESS(bus)*SOCmax/sbase)$(ord(t)=1)+SOC(bus,t-1)$(ord (t)>1)+(Pc(bus,t)$SOCmax(bus)*eta_c)-(Pd(bus,t)$SOCmax(bus)/eta_d);
constESS2(bus,t) .. SOC(bus,t)=l=NESS(bus)*SOCmax/sbase ;
*P_max charge
constESS3(bus,t) .. Pc(bus,t)=l=0.2*NESS(bus)*SOCmax/sbase ;
*P_max discharge
constESS4(bus,t) .. Pd(bus,t)=l=0.2*NESS(bus)*SOCmax/sbase ;
*limit on total ESSs
constESS5 .. sum(bus,NESS(bus))=l=Nmax;
*final SoC imposition (SoC0=0.2*SOCmax)
constESS6(bus) .. SOC(bus,’t24′)=e=0.2*NESS(bus)*SOCmax/sbase ;
objfnc..OF=e=sum((bus,Gen,t)$GB(Gen,bus),Pg(Gen,t)*Gendata(Gen,’b’)*sbase)+sum((bus,t),VOLL*lsh(bus,t)*sbase$(busdata(bus,’Pd’))+VOLW*pwc(bus,t)*Sbase$(Wcap(bus)));
Model load_flow/all/;
Pij.lo(bus,node,t)$(conex(bus,node))=-1*branches(bus,node,’limit’)/sbase;
Pij.up(bus,node,t)$(conex(bus,node))=1*branches(bus,node,’limit’)/sbase;
Pg.lo(Gen,t)=GD(Gen,’Pmin’)/sbase;
Pg.up(Gen,t)=GD(Gen,’Pmax’)/sbase;
delta.lo(bus,t)=-pi/2;
delta.up(bus,t)=pi/2;
delta.fx(slack,t)=0;
Pc.lo(bus,t)=0;
Pd.lo(bus,t)=0;
SOC.lo(bus,t)=0;
NESS.up(bus)=5;
Nmax=110;
pw.lo(bus,t)=0;
pw.up(bus,t)=WD(t,’w’)*Wcap(bus)/Sbase;
pwc.lo(bus,t)=0;
pwc.up(bus,t)=WD(t,’w’)*Wcap(bus)/Sbase;
lsh.lo(bus,t)=0;
lsh.up(bus,t)=WD(t,’d’)*busdata(bus,’Pd’)/Sbase;
Solve load_flow using MIP minimizing OF;
set stat /bestpossible,objective,tgams,tsolver,modelstat,solvestat/;
parameter returnStat(stat);
returnStat(‘bestpossible’) = loadflow.objest;
returnStat(‘objective’) = loadflow.objval;
returnStat(‘tsolver’) = loadflow.resusd;
returnStat(‘modelstat’) = loadflow.modelstat;
returnStat(‘solvestat’) = loadflow.solvestat;
execute_unload %matout1%
display Pg.l,Pij.l,delta.l, pwc.l,lsh.l,Pc.l,Pd.l; Hi, please someone tell me regarding integration of MATLAB code with GAMS, i want to implement DCOPF. I receive this error in MATLAB:Error using wgdx:Amount of full format .val data exceeds number of UELs. Please try to resolve it, is my wgdx and rgdx functions working?
This is my MATLAB code:
clear all
close all
clc
%inputs
mpc=load (‘grid_data_24bus.mat’);
profile_L=mpc.WD(:,3);
profile_gen_rand=[1.0057;1.027;0.98;0.967;0.9837;0.971;1.001;1.04063;1.0129;0.961;0.989;0.9554;1.000129;0.9937;1.0497;1.0316;0.9986;1.03944;0.963;0.989;1.0427;1.041749;1.0214;1.0118];
n_time = 24; % time intervals
DeltaT = 24/n_time; % granularity
n_bus = size(mpc.BusData,1); % Number of buses
n_brnc = size(mpc.branches,1); % Number of branches
n_gen = size(mpc.Gen,1); % num of generators
slack = 13; % slack choice
VS = 1; % default value for slack voltage
V_up=1.1; % Voltage limits
V_lo=0.9; % Voltage limits
% Time profiles
mpc.BusData = repmat (mpc.BusData, [1,1,n_time]);
mpc.Gen = repmat (mpc.Gen, [1,1,n_time]);
for t=1:n_time
mpc.BusData(:,2,t)=profile_L(t).*mpc.BusData(:,2,t);% column 2 have Pd
for g=1:size(mpc.Gen,1)
mpc.Gen(g,3:4,t)=profile_gen_rand(t).*( mpc.Gen(g,3:4,t));%pmax and pmin
end
end
mpc_pre=mpc; %save mpcstruct
%%% ESS allocation
SOC_max = 100; % battery size [MWh]
SOC_0 = 0.2*SOC_max/mpc.Sbase; % initial SoC [per unit]
eta_c = 0.95; % charge efficiency
eta_d = 0.9; % discharge efficiency
VOLL = 10000; % Value of Loss of Load
VWC = 50; % Value of loss of wind ($/MWh)
% Define Wind Capacity and Generation Profiles for Specific Buses
% Define Wind Capacity and Generation Profiles for Specific Buses
Wcap = zeros(n_bus, 1); % Wind capacity array for all buses
Wcap(8) = 200; % Bus 8: 200 MW
Wcap(19) = 150; % Bus 19: 150 MW
Wcap(21) = 100; % Bus 21: 100 MW
% Wind data over 24 hours (from ‘w’ column)
wind_profile = mpc.WD(:, 2); % 24-hour wind profile
% Wind Generation Matrix (Buses x Time)
wind_gen = Wcap * wind_profile’; % Corrected dimensions
% sending data to GAMS
% Time index for GAMS file
TT=cell(1,n_time);
for tt=1:n_time
TT{tt}=[‘t’,num2str(tt)];
end
y.name=’t’;
y.type=’set’;
y.uels=TT;
% Nodes
bus = linspace(1,n_bus,n_bus)’;
Bus.name=’bus’;
Bus.type=’set’;
Bus.uels=num2cell(bus)’;
% Slack bus
Slack.name=’slack’;
Slack.type=’set’;
Slack.val=slack;
Slack.uels=Bus.uels;
% Generators
GG=cell(1,n_gen);
for gg=1:n_gen
GG{gg}=[‘g’,num2str(gg)];
end
gen.name=’Gen’;
gen.type=’set’;
gen.uels=GG;
% S_base
S_base.name=’sbase’;
S_base.type=’parameter’;
S_base.val=mpc.Sbase;
S_base.form=’full’;
S_base.dim=0;
% VOLL
VoLL.name=’VOLL’;
VoLL.type=’parameter’;
VoLL.val=VOLL;
VoLL.form=’full’;
VoLL.dim=0;
% Value wind curtailment
Vwc.name=’VWC’;
Vwc.type=’parameter’;
Vwc.val=VWC;
Vwc.form=’full’;
Vwc.dim=0;
% Charge efficiency []
Eta_c.name=’eta_c’;
Eta_c.type=’parameter’;
Eta_c.val=eta_c;
Eta_c.form=’full’;
Eta_c.dim=0;
% Discharge efficiency []
Eta_d.name=’eta_d’;
Eta_d.type=’parameter’;
Eta_d.val=eta_d;
Eta_d.form=’full’;
Eta_d.dim=0;
% Maximum battery SoC [MWh]
socmax.name=’SOCmax’;
socmax.type=’parameter’;
socmax.val=SOC_max;
socmax.form=’full’;
socmax.dim=0;
% Initial battery SoC [0-1]
socini.name=’SOC0′;
socini.type=’parameter’;
socini.val=SOC_0;
socini.form=’full’;
socini.dim=0;
% Wind and load power profiles []
%WD(t,*) wind-demand daily variation patterns: ‘w’ wind ‘d’ demand
wd.name=’WD’;
wd.type=’parameter’;
wd.val=mpc.WD(:,2:3);
wd.form=’full’; %missing indices are zero
wd.dim=2;
wd.uels={TT,{‘w’,’d’}};
% Branches data
%branches(bus,node,*) ‘r(pu)’ ‘x(pu)’ ‘b(pu)’ ‘limit(MVA)’
branches = [];
for ii=1:size(branches,1)
branches=vertcat(branches, zeros(4,4));
branches((ii-1)*4+1:ii*4,:)=….
[ branches(ii,1) branches(ii,2) 1 branches(ii,3); … from to ‘r’ value
branches(ii,1) branches(ii,2) 2 branches(ii,4); … from to ‘x’ value
branches(ii,1) branches(ii,2) 3 branches(ii,5); … from to ‘b’ value
branches(ii,1) branches(ii,2) 4 branches(ii,6) ]; … from to ‘limit’ value
end
Branches.name=’branches’;
Branches.type=’parameter’;
Branches.val=mpc.Branches;
Branches.form=’sparse’; %missing indices are zero
Branches.uels={Bus.uels, Bus.uels, {‘r’,’x’,’b’,’limit’}};
Branches.dim=3;
% Gen bus location
gb.name=’GB’;
gb.type=’set’;
gb.val=mpc.Gen(:,1:2); %GB(Gen,bus) generating buses
gb.val(:,1) = 1:n_gen;
gb.form=’sparse’;
gb.dim=2;
gb.uels={gen.uels,{1:24}}; % Covering all 24 buses in the system
% Gen data
GenData=[mpc.Gen(:,5)’; mpc.Gen(:,4)’; mpc.Gen(:,3)’; mpc.Gen(:,8)’; mpc.Gen(:,9)’]’; %GenData GD(Gen,*) ‘b’ ‘pmin’ ‘pmax’ ‘RU’ ‘RD’ -> ‘b’ t.c. Gen_cost = a*Pg^2 + b*Pg + c
Gen_Data.name=’GD’;
Gen_Data.type=’parameter’;
Gen_Data.val=GenData;
Gen_Data.form=’full’;
Gen_Data.dim=2;
Gen_Data.uels={GG,{‘b’,’pmin’,’pmax’,’RU’,’RD’}};
% Define the WCap parameter
WCap.name = ‘Wcap’; % Parameter name
WCap.type = ‘parameter’; % Define it as a parameter
WCap.val = Wcap; % Assign wind capacity values from Wcap
WCap.form = ‘full’; % Missing indices are assumed zero
WCap.dim = 1; % One-dimensional parameter (indexed by buses)
WCap.uels = {Bus.uels}; % Link the parameter to the bus indices
% Bus data
Bus_Data.name=’BusData’;
Bus_Data.type=’parameter’;
Bus_Data.val=[mpc.BusData(:,1) ones(size(mpc.BusData,1),1) mpc.BusData(:,2) mpc.BusData(:,1) 2*ones(size(mpc.BusData,1),1) mpc.BusData(:,3)];
Bus_Data.val=reshape(Bus_Data.val’, [size(Bus_Data.val’,1)/2,size(Bus_Data.val’,2)*2]);
Bus_Data.val=Bus_Data.val’;
Bus_Data.form=’sparse’;
Bus_Data.dim=2;
Bus_Data.uels={Bus.uels,{‘Pd’,’Qd’}};
%% GAMS calculation
GAMSfolder=[];
wgdxName=’dcopf_bess’;
% write gdx file as input for GAMS model
wgdx(wgdxName,y,gen,Bus,Slack,S_base,VoLL,Vwc,Eta_c,Eta_d,socmax,socini,wd,gb,Gen_Data,WCap,Bus_Data,Branches);
% gdxInfo DC_OPF %to print and check gdx input file
% run Gams file
gams([ ‘dcopf_bess’ ‘ lo=2’ ]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% read the gdx output file from GAMS
solGDX=[GAMSfolder ‘dcopf_bess_Solution.gdx’];
rs = struct(‘name’,’returnStat’,’compress’,’true’);
stats = rgdx(solGDX,rs);
gdxInfo DC_OPF_Solution %print gdx results
%matout file contains:
%OF, Pij(bus,node,t), delta(bus,t),
%Pg(Gen,t), lsh (bus,t), Pw(bus,t), pwc(bus,t),
%SOC(bus,t), Pd(bus,t), Pc(bus,t),NESS(bus);
% print of the stats of the GAMS run
disp([‘Best possible: ‘,num2str(stats.val(1,2))]);
disp([‘Objective: ‘,num2str(stats.val(2,2))]);
disp([‘Optimality gap: ‘,num2str((stats.val(2,2)-stats.val(1,2))/(stats.val(1,2))*100),’ %’]);
disp([‘Time: ‘,num2str(stats.val(3,2)), ‘ s’]);
disp([‘Model status: ‘,num2str(stats.val(4,2)), ‘(1: optimal, 8: integer solution model found)’]);
disp(‘Done!’)
disp(‘ ‘)
%% Results
% reading of the results related to charge power
P_c = struct(‘name’,’Pc’,’form’,’sparse’,’compress’,’true’);
sP_c=rgdx(solGDX,P_c);
P_c = zeros(n_bus,n_time);
for ijk=1:length(sP_c.val(:,3))
P_c(sP_c.val(ijk,1),sP_c.val(ijk,2)) = sP_c.val(ijk,3);
end
% reading of the results related to discharge power
P_d = struct(‘name’,’Pd’,’form’,’sparse’,’compress’,’true’);
sP_d=rgdx(solGDX,P_d);
P_d = zeros(n_bus,n_time);
for ijk=1:length(sP_d.val(:,3))
P_d(sP_d.val(ijk,1),sP_d.val(ijk,2)) = sP_d.val(ijk,3);
end
% reading of the results related to the State of Charge
SoC_batt=struct(‘name’,’SOC’,’form’,’full’,’compress’,’true’);
sSoC_B=rgdx(solGDX,SoC_batt);
SoC = zeros(n_bus,n_time);
SoC = sSoC_B.val;
% reading of the results related to number of batteries
NESS=struct(‘name’,’NESS’,’form’,’full’,’compress’,’true’);
sNESS=rgdx(solGDX,NESS);
idx = str2double(sNESS.uels{1});
N_ESS = zeros(n_bus,1);
N_ESS(idx) = sNESS.val;
figure;
stairs(N_ESS)
xlabel(‘bus number’)
ylabel(‘Number of ESS’)
ylim([0 max(N_ESS)+0.2])
% reading of the results related to generators
P_gen=struct(‘name’,’Pg’,’form’,’full’,’compress’,’true’);
sP_gen=rgdx(solGDX,P_gen);
P_gen = zeros(n_gen,n_time);
P_gen = sP_gen.val;
% wind curtailment result
P_cut=struct(‘name’,’pwc’,’form’,’full’,’compress’,’true’);
sP_Cut=rgdx(solGDX,P_cut);
P_cur = zeros(n_bus,n_time);
P_cur = sP_Cut.val;
% load shedding result
P_sh=struct(‘name’,’lsh’,’form’,’full’,’compress’,’true’);
sP_sh=rgdx(solGDX,P_sh);
Psh = zeros(n_bus,n_time);
Psh = sP_sh.val;
figure;
plot(P_cur)
hold on
plot(Psh)
hold off
xlabel(‘time [h]’)
ylabel(‘Wind curtailment and load shedding’)
legend(‘Curtailment’,’Load shedding’)
% Pij flows result
P_ij = struct(‘name’,’Pij’,’form’,’sparse’,’compress’,’true’);
sP_ij=rgdx(solGDX,P_ij);
P_ij = zeros(n_bus, n_bus, n_time); % If Pij is bus-to-bus over time
for ijk=1:length(sP_ij.val(:,3))
P_ij(sP_ij.val(ijk,1), sP_ij.val(ijk,2), sP_ij.val(ijk,3)) = sP_ij.val(ijk,4);
end
% Plotting power flow between bus i and bus j over time
i = 1; % Sending bus
j = 2; % Receiving bus
figure;
stairs(1:n_time, squeeze(P_ij(i,j,:)));
xlabel(‘Time’);
ylabel([‘Power flow from bus ‘, num2str(i), ‘ to bus ‘, num2str(j)]);
title(‘Power Flow between Buses over Time’);
This is integration with GAMS to see its output:
$set matout1 "’dcopf_bess_Solution.gdx’,returnStat,t,OF,Pd,Pc,SOC,Pij,Pg,lsh,pwc"
Sets
t time
DeltaT granularity
bus buses
Gen generators
GB(Gen,bus) generators’ bus location
slack(bus) slack bus;
alias(bus,node);
scalar
sbase base power
V_up upper voltage limit
V_lo lower voltage limit
eta_c charge efficiency
eta_d discharge efficiency
VWC Value of Wind curtailment
VOLL Value of Loss of Load;
parameters
SOCmax battery size [MWh]
SOC0 initial SoC [per unit]
GD(Gen,*) Generator data
branches(bus,node,*) r(pu) x(pu) b(pu) limit(MVA)
WD(t,*) Wind-demand daily variation patterns: ‘w’ wind ‘d’ demand
Wcap(bus) Wind capacities
BusData(bus,*) Demands of each bus in MW;
$gdxin "C:UsersuserDesktopmatpower7.1datadcopf_bess.gdx"
$load t Gen sbase bus slack VOLL VWC eta_c eta_d SOCmax SOC0 WD GD GB WCap BusData branches
$gdxin
Scalars Nmax;
branches(bus,node,’x’)$(branches(bus,node,’x’)=0)=branches(node,bus,’x’);
branches(bus,node,’limit’)$(branches(bus,node,’limit’)=0)=branches(node,bus,’limit’);
branches(bus,node,’bij’)$(conex(bus,node))=1/branches(node,bus,’x’);
Parameter conex(bus,node) Bus connectivity matrix;
conex(bus,node)$(conex(node,bus))=1;
conex(bus,node)$(branches(bus,node,’limit’) and branches(node,bus,’limit’)) =1;
Variables OF, Pij(bus,node,t),Pg(Gen,t),delta(bus,t), pw(bus,t),lsh(bus,t),SOC(bus,t),pwc(bus,t),Pd(bus,t),Pc(bus,t);
Integer variable NESS(bus);
Equations objfnc, balance,const1,const2,const3,const4,constESS,constESS2,constESS3(bus,t),constESS4(bus,t),constESS5(bus,t),constESS6(bus,t);
balance(bus,t)..sum(node$(conex(node,bus)),Pij(bus,node,t))=e=sum(Gen$(GB(Gen,bus)),Pg(Gen,t))+lsh(bus,t)$busdata(bus,’Pd’)+pw(bus,t)$Wcap(bus)-Pc(bus,t)$SOCmax(bus)+Pd(bus,t)$SOCmax(bus)-WD(t,’d’)*busdata(bus,’Pd’)/sbase;
const1(bus,node,t)$conex(bus,node)..Pij(bus,node,t)=e=branches(bus,node,’bij’)*(delta(bus,t)-delta(node,t));
const2(Gen,t)..Pg(Gen,t+1)-Pg(Gen,t)=l=Gendata(Gen,’RU’)/sbase;
const3(Gen,t)..Pg(Gen,t-1)-Pg(Gen,t)=l=Gendata(Gen,’RD’)/sbase;
const4(bus,t)$Wcap(bus)..pwc(bus,t)=e=WD(t,’w’)*Wcap(bus)/sbase-pw(bus,t);
constESS(bus,t)$SOCmax(bus)..SOC(bus,t)=e=(0.2*NESS(bus)*SOCmax/sbase)$(ord(t)=1)+SOC(bus,t-1)$(ord (t)>1)+(Pc(bus,t)$SOCmax(bus)*eta_c)-(Pd(bus,t)$SOCmax(bus)/eta_d);
constESS2(bus,t) .. SOC(bus,t)=l=NESS(bus)*SOCmax/sbase ;
*P_max charge
constESS3(bus,t) .. Pc(bus,t)=l=0.2*NESS(bus)*SOCmax/sbase ;
*P_max discharge
constESS4(bus,t) .. Pd(bus,t)=l=0.2*NESS(bus)*SOCmax/sbase ;
*limit on total ESSs
constESS5 .. sum(bus,NESS(bus))=l=Nmax;
*final SoC imposition (SoC0=0.2*SOCmax)
constESS6(bus) .. SOC(bus,’t24′)=e=0.2*NESS(bus)*SOCmax/sbase ;
objfnc..OF=e=sum((bus,Gen,t)$GB(Gen,bus),Pg(Gen,t)*Gendata(Gen,’b’)*sbase)+sum((bus,t),VOLL*lsh(bus,t)*sbase$(busdata(bus,’Pd’))+VOLW*pwc(bus,t)*Sbase$(Wcap(bus)));
Model load_flow/all/;
Pij.lo(bus,node,t)$(conex(bus,node))=-1*branches(bus,node,’limit’)/sbase;
Pij.up(bus,node,t)$(conex(bus,node))=1*branches(bus,node,’limit’)/sbase;
Pg.lo(Gen,t)=GD(Gen,’Pmin’)/sbase;
Pg.up(Gen,t)=GD(Gen,’Pmax’)/sbase;
delta.lo(bus,t)=-pi/2;
delta.up(bus,t)=pi/2;
delta.fx(slack,t)=0;
Pc.lo(bus,t)=0;
Pd.lo(bus,t)=0;
SOC.lo(bus,t)=0;
NESS.up(bus)=5;
Nmax=110;
pw.lo(bus,t)=0;
pw.up(bus,t)=WD(t,’w’)*Wcap(bus)/Sbase;
pwc.lo(bus,t)=0;
pwc.up(bus,t)=WD(t,’w’)*Wcap(bus)/Sbase;
lsh.lo(bus,t)=0;
lsh.up(bus,t)=WD(t,’d’)*busdata(bus,’Pd’)/Sbase;
Solve load_flow using MIP minimizing OF;
set stat /bestpossible,objective,tgams,tsolver,modelstat,solvestat/;
parameter returnStat(stat);
returnStat(‘bestpossible’) = loadflow.objest;
returnStat(‘objective’) = loadflow.objval;
returnStat(‘tsolver’) = loadflow.resusd;
returnStat(‘modelstat’) = loadflow.modelstat;
returnStat(‘solvestat’) = loadflow.solvestat;
execute_unload %matout1%
display Pg.l,Pij.l,delta.l, pwc.l,lsh.l,Pc.l,Pd.l; power system MATLAB Answers — New Questions
Why can’t I publish in FileExchange?
When I link with the github public repository and prepare to publish, I get a publish error and the status bar keeps showing this? What can I do to secure the release?When I link with the github public repository and prepare to publish, I get a publish error and the status bar keeps showing this? What can I do to secure the release? When I link with the github public repository and prepare to publish, I get a publish error and the status bar keeps showing this? What can I do to secure the release? fileexchange, opensource MATLAB Answers — New Questions
How do I use a class property validation function with a dynamic argument?
In Matlab OOP, I wanna use a function like mustBeEqualSize(a,b) from the Examples on function property validation to validate a property:
classdef foo
properties
a
b {mustBeEqualSize(a,b)}
end
end
However, this gives me an error.In Matlab OOP, I wanna use a function like mustBeEqualSize(a,b) from the Examples on function property validation to validate a property:
classdef foo
properties
a
b {mustBeEqualSize(a,b)}
end
end
However, this gives me an error. In Matlab OOP, I wanna use a function like mustBeEqualSize(a,b) from the Examples on function property validation to validate a property:
classdef foo
properties
a
b {mustBeEqualSize(a,b)}
end
end
However, this gives me an error. matlab, oop MATLAB Answers — New Questions
CCCV Charging of Batteries does not works
Hi Community,
I have created a Panasonic Battery Pack NCR18650BD arrange in the following configuration 6S1P. However my model does not works and the battery does not charge up at all using CCCV? I just get a flat curve throughout. The current does not even goes to the charge current of 1.375A
Does anyone have any idea how to resolve this issue?
The settings are as follow:
Initial SOC
[0.3 0.3 0.3 0.3 0.3 0.3]
Relay Settings:
0.9 Turn On
0.3 Turn Off
CCCV Settings:
Maximum Cell Settings: 4.2
Controller Proportional Gain:100
Controller Integral Gain:10
Controller Anti Windup Gain:1
Gain of Signal Feedback Tracking Loop: 1
Sample Time: 1
Unit Delay:
Initial Condition: 0
Attached are the images and the code below.Hi Community,
I have created a Panasonic Battery Pack NCR18650BD arrange in the following configuration 6S1P. However my model does not works and the battery does not charge up at all using CCCV? I just get a flat curve throughout. The current does not even goes to the charge current of 1.375A
Does anyone have any idea how to resolve this issue?
The settings are as follow:
Initial SOC
[0.3 0.3 0.3 0.3 0.3 0.3]
Relay Settings:
0.9 Turn On
0.3 Turn Off
CCCV Settings:
Maximum Cell Settings: 4.2
Controller Proportional Gain:100
Controller Integral Gain:10
Controller Anti Windup Gain:1
Gain of Signal Feedback Tracking Loop: 1
Sample Time: 1
Unit Delay:
Initial Condition: 0
Attached are the images and the code below. Hi Community,
I have created a Panasonic Battery Pack NCR18650BD arrange in the following configuration 6S1P. However my model does not works and the battery does not charge up at all using CCCV? I just get a flat curve throughout. The current does not even goes to the charge current of 1.375A
Does anyone have any idea how to resolve this issue?
The settings are as follow:
Initial SOC
[0.3 0.3 0.3 0.3 0.3 0.3]
Relay Settings:
0.9 Turn On
0.3 Turn Off
CCCV Settings:
Maximum Cell Settings: 4.2
Controller Proportional Gain:100
Controller Integral Gain:10
Controller Anti Windup Gain:1
Gain of Signal Feedback Tracking Loop: 1
Sample Time: 1
Unit Delay:
Initial Condition: 0
Attached are the images and the code below. simscape, battery_system_management, cccv MATLAB Answers — New Questions
Delete button on unverified sender emails
We want these warnings to Stop on certain automated emails, but we want to continue to receive the messages.
Is the Delete button to delete the warning, or delete the messages, and block the messages? Or?
How do we Verify this sender?
We want these warnings to Stop on certain automated emails, but we want to continue to receive the messages. Is the Delete button to delete the warning, or delete the messages, and block the messages? Or?How do we Verify this sender? Read More
Versa SASE client push
Has anyone pushed VERSA SASE client through Intune to devices? I am having issues with the detection rules and it does not upgrade nor it does not uninstall the existing version and I am struggling to get this working.
Any help or suggestions would be great. It is not upgrading or uninstalling the previous version to get this working. I tried everything possible, I am pushing it to devices and now I am trying using user group. Not sure that would make any difference, earlier the previous version 7.8.9 was pushed to all devices. It worked fine with the same syntax.
Even Microsoft is struggling and not sure what to do.
Has anyone pushed VERSA SASE client through Intune to devices? I am having issues with the detection rules and it does not upgrade nor it does not uninstall the existing version and I am struggling to get this working. Any help or suggestions would be great. It is not upgrading or uninstalling the previous version to get this working. I tried everything possible, I am pushing it to devices and now I am trying using user group. Not sure that would make any difference, earlier the previous version 7.8.9 was pushed to all devices. It worked fine with the same syntax. Even Microsoft is struggling and not sure what to do. Read More
Task Title Integration between OneNote and To Do
OneNote has a great tool where you can create a task with a due date, and once created, this taskk appears as a task in Microsoft To Do. When the task due date is amended (e.g. moved to a later date) in OneNote, this is reflected in To Do, but if the Task Title is changed, this is not reflected in To Do. Am i doing something wrong?
OneNote has a great tool where you can create a task with a due date, and once created, this taskk appears as a task in Microsoft To Do. When the task due date is amended (e.g. moved to a later date) in OneNote, this is reflected in To Do, but if the Task Title is changed, this is not reflected in To Do. Am i doing something wrong? Read More
Issue with Device Control Policy Sync in Intune/MDE
Hello,
We onboarded devices to Microsoft Defender for Endpoint through Intune in a co-management environment, with Endpoint Protection workload shifted to Intune. We configured a Device Control policy, which is blocking installation of USB devices like keyboards and mouse. Despite removing the USB blocking settings, syncing devices via Intune, and rebooting the devices, USB devices were still blocked after several hours.
Running the `Get-MpComputerStatus` command on affected devices showed an outdated `DeviceControlPoliciesLastUpdated` date (year 1601).
Could anyone advise on how long it typically takes for policy changes in Intune/MDE to take effect? Is there a way to manually force policy sync across all devices?
Thanks in advance for your help
Hello,We onboarded devices to Microsoft Defender for Endpoint through Intune in a co-management environment, with Endpoint Protection workload shifted to Intune. We configured a Device Control policy, which is blocking installation of USB devices like keyboards and mouse. Despite removing the USB blocking settings, syncing devices via Intune, and rebooting the devices, USB devices were still blocked after several hours.Running the `Get-MpComputerStatus` command on affected devices showed an outdated `DeviceControlPoliciesLastUpdated` date (year 1601).Could anyone advise on how long it typically takes for policy changes in Intune/MDE to take effect? Is there a way to manually force policy sync across all devices?Thanks in advance for your help Read More
Cannot edit event in Web Part Calendar
Hello,
I am trying to add a calendar web-part to a site page to create a collaborative team calendar. While I can add new events, once they are added, I can’t edit these. It opens a popup and doesn’t populate it. [Just spins forever]
I have tried to delete calendar and re-add another but it adds the same events to the new calendar.
I’ve tested across browsers and across OS with the same result.
Is this a known issue or advice is appreciated.
Hello,I am trying to add a calendar web-part to a site page to create a collaborative team calendar. While I can add new events, once they are added, I can’t edit these. It opens a popup and doesn’t populate it. [Just spins forever]I have tried to delete calendar and re-add another but it adds the same events to the new calendar.I’ve tested across browsers and across OS with the same result.Is this a known issue or advice is appreciated. Read More
Calendar, contact syncronisation on prem Exchange 2016 with M365 outlook
Good afternoon!
I would like help.
We have a subscription to M365 Enterprise Standard.
We currently run our mail on an on-premises Exchange 2016 server with outlook clients.
There have been several issues recently with users who also use outlook on mobile failing to connect to on-premises mail after changing their password.
Under Android 14 there is no way to set up outlook because it only allows you to connect to the cloud account, not exchange.
I would like to solve this problem, but I don’t want to outsource our mail to the cloud because we don’t have cloud backup.
My first option would be to try to redirect the correspondence to the M365 account, but I don’t know how to set up the synchronization of calendar, contacts?
Thank you for your answer.
Laszlo
Good afternoon! I would like help.We have a subscription to M365 Enterprise Standard.We currently run our mail on an on-premises Exchange 2016 server with outlook clients.There have been several issues recently with users who also use outlook on mobile failing to connect to on-premises mail after changing their password.Under Android 14 there is no way to set up outlook because it only allows you to connect to the cloud account, not exchange.I would like to solve this problem, but I don’t want to outsource our mail to the cloud because we don’t have cloud backup.My first option would be to try to redirect the correspondence to the M365 account, but I don’t know how to set up the synchronization of calendar, contacts? Thank you for your answer.Laszlo Read More
How to Migrate from WP Engine to WordPress on App Service?
WordPress on App Service, a managed offering by Microsoft, is designed to elevate your WordPress hosting experience. This innovative solution leverages the robust capabilities of Azure App Service and Azure Database for MySQL to provide an unparalleled hosting environment for your WordPress sites. Additionally, we offer:
Managed but Flexible Offering: We handle all upgrades behind the scenes, so you don’t have to worry about the underlying technology. This allows you to focus on building your best WordPress site. We also avoid forcing major upgrades on you, minimizing the risk of your site breaking. You have the time and flexibility to test your application and switch to an upgraded stack when you’re ready. Similarly, with WordPress core, security patches are automatic, but you decide how to manage major upgrades.
Unmatched Security: The built-in security features of Azure App Service and Azure Database for MySQL ensure your data and applications are protected with the highest standards of security. Additionally, Azure VNET and Azure Entra ID managed identities enhance your security posture.
Superior Performance: Benefit from numerous performance enhancements such as built-in Redis cache and local storage caching. Seamless integration with Azure CDN or Azure Front Door and Azure Blob Storage ensures your WordPress site operates with optimal speed and efficiency.
Effortless Setup and Management: The easy creation wizard simplifies the setup process, while the Azure portal provides a user-friendly interface for managing your site. Customization is straightforward with the use of ARM templates and Azure CLI, allowing you to tailor the offering to your specific requirements.
Authentic WordPress Experience: We maintain the integrity of the WordPress core, providing authentic WordPress experience. You have the flexibility to use plugins like W3 Total Cache for integration with Azure CDN or Azure Front Door and storage or select your preferred plugins to meet your needs.
Comprehensive Integration: This offering harnesses the power of Azure App Service and Azure Database for MySQL to host your WordPress web app and database, respectively. The entire setup is configured with an Azure VNET for added security, ensuring seamless and secure integration. Plus, you can choose to integrate with various other Azure services out of the box, making it easy to use additional services without manual configuration.
We invite you to make the switch to WordPress on App Service and experience the power, security, and performance of Azure. Transform your WordPress hosting experience and delight your customers!
In the next section, I will provide you with a step-by-step guide on how to migrate your WordPress sites from WP Engine to WordPress on App Service.
Note: For the migration, we will use the All-in-One WP Migration and Backup plugin, which we highly recommend. Our example covers a single site to single site migration. If you’re dealing with WP multisites, you’ll need the Multisite extension for the All-in-One Migration plugin. We will export the site as a zip file and download it to our local machine. If you prefer using FTP or exporting to services like Dropbox, Azure Storage, Amazon S3, etc., there are extensions available for those as well. You can find all the extensions here: https://servmask.com/products.
Additionally, the plugin offers advanced functionalities. You can search and replace strings in your database or exclude specific items from the export, such as comments or plugins. These features are intended for advanced users, and we recommend using them only if you are confident in what you’re doing. In this tutorial, we have not utilized any advanced features. To learn more about these features, you can find many helpful videos on their YouTube channel: https://www.youtube.com/@Servmask/videos
PART 1: ON WP ENGINE
I will be using a demo website hosted on WP Engine in this tutorial. https://wpcontoso.wpenginepowered.com/
Step 1: Go to wp-admin of your WordPress site and install and activate the plugin ‘All-in-One WP Migration and Backup” https://wordpress.org/plugins/all-in-one-wp-migration/
Step 2: Go to All-in-One WP migration tab on the left-hand pane. Click on ‘EXPORT TO’ > FILE.
This will start the backup process.
Step 3: Once the backup is ready click on the DOWNLOAD dialog button.
The entire website content will be downloaded to you local machine.
PART 2. ON AZURE
Step 1: Create a new WordPress site on App Service. Follow the steps here: https://techcommunity.microsoft.com/t5/apps-on-azure-blog/how-to-set-up-a-new-wordpress-website-on-azure-app-service/ba-p/3729150
I have created this site for demo: https://wpcontoso.azurewebsites.net/
Step 2: Go to wp-admin of your WordPress site on Azure. Install and activate All-in-One Migration and Backup plugin.
Step 3: Go to the ‘All-in-One Migration’ tab > ‘Import’ Option on the left-hand pane. Click on IMPORT FROM > FILE. Note: You might need to increase upload size limits. Refer: https://github.com/Azure/wordpress-linux-appservice/blob/main/WordPress/wordpress_application_settings.md
Then select the file from your local machine. This will start the upload process.
Do not close the window until the Import process is completed.
Step 4: Now you will see that the site has been imported.
PART 3. ADDITIONAL STEPS
Step 1: To take advantage of caching and email, please make sure that you re-activate the W3 Total Cache and App Service Email plugins. They were deactivated because they were not installed in the WP Engine environment. You might also need to purge the cache.
Step 2: Remove WP engine files that you do not need in the App Service environment. Remove the following files and folders.
wp-content/advanced-cache.php
wp-content/object-cache.php
wp-content/mu-plugins/mu-plugin.php
wp-content/mu-plugins/wpengine-common/
wp-content/mu-plugins/slt-force-strong-passwords.php
wp-content/mu-plugins/force-strong-passwords/
wp-content/mu-plugins/stop-long-comments.php
wp-content/mu-plugins/wpe-wp-sign-on-plugin/
wp-content/mu-plugins/wpe-wp-sign-on-plugin.php
wp-content/mu-plugins/wpengine-security-auditor.php
Try out this migration process today and let us know how it went!
Support and Feedback
Did you like this article? Please click on like if you do. Also, leave your comments, and help us to make this article better.
If you need any assistance, feel free to open a support request through the Microsoft Azure portal.
You can also report an issue on our GitHub repository Issues
For more details about our offering, check out the announcement on the General Availability of WordPress on Azure App Service.
Also, you can find here additional documentation related to WordPress on App Service.
You can share your thoughts and suggestions on our community page.
Would love to know about your experience & issues you are facing, and you can start a conversation with us by emailing to wordpressonazure@microsoft.com
Microsoft Tech Community – Latest Blogs –Read More
EnterpriseDB and Revers.io offer transactable partner solutions in Azure Marketplace
Microsoft partners like EnterpriseDB and Revers.io deliver transact-capable offers, which allow you to purchase directly from Azure Marketplace. Learn about these offers below:
EDB: Postgres-as-a-Service: PostgreSQL is a popular database among organizations looking to boost innovation and accelerate business. EDB’s enterprise-class software extends Postgres with native AI vector processing, an analytics lakehouse, and a unified platform for observability and hybrid data management.
Revers.io: After-sales PLM: Revers.io is an omnichannel product lifecycle management platform that connects every stakeholder and simplifies the after-sales experience, supporting your digital transformation while reducing operational costs and environmental impacts. Get a 360-degree view on returns and focus on what really matters: customer satisfaction.
Microsoft Tech Community – Latest Blogs –Read More
Error using sqpInterface Nonlinear constraint function is undefined at initial point. Fmincon cannot continue.
I got this error "Nonlinear constraint function is undefined at initial point. Fmincon cannot continue." when i ran a simulation to remove offset using extended kalman filter "EKF" in quadruple system. The target is to control level of water in the lower tank h1 and h2 by manipulating v1 and v2. check below for the code;
NMPC CODE:
clc, clear all
%% Simulink Model
% To run this example, Simulink(R) is required.
if ~mpcchecktoolboxinstalled(‘simulink’)
disp(‘Simulink is required to run this example.’)
return
end
%%initialize NMPC object and set properties
nx = 8;
ny = 2;
%nu = 2;
%’UD’, [5,6,7,8,9,10]
nlobj = nlmpc(nx, ny, ‘MV’, [1,2], ‘UD’, [3,4,5,6]);
%The prediction model sample time is the same as the controller sample time
Ts = 3; %Ts = 2
nlobj.Ts = Ts;
%Prediction and control horizon
nlobj.PredictionHorizon = 20;
nlobj.ControlHorizon = [1];
%weights on output and manipulated variables
nlobj.Weights.OutputVariables = [1000,1000]; %0.1
nlobj.Weights.ManipulatedVariables = [10,10]; %0.05;
%nlobj.Weights.ManipulatedVariablesRate = [10,10];
%constraints on manipulated variables
nlobj.MV(1).RateMin = -1;
nlobj.MV(2).RateMin = -1;
nlobj.MV(1).RateMax = 1;
nlobj.Mv(2).RateMax = 1;
nlobj.MV(1).Min = 2.7;
nlobj.MV(2).Min = 2.7;
nlobj.MV(1).Max = 3.3;
nlobj.MV(1).Max = 3.3;
%constraint on output variables to keep them within reasonable bounds
nlobj.OV(1).Min = 11.16;
nlobj.OV(2).Min = 11.43;
%nlobj.OV(3).Min = 2.5;
%nlobj.OV(4).Min = 2.5;
nlobj.OV(1).Max = 13.64;
nlobj.OV(2).Max = 13.97;
%nlobj.OV(3).Max = 8;
%nlobj.OV(4).Max = 8;
%% specify the nonlinear state and output functions
nlobj.Model.StateFcn = ‘four_tankStateFcnCT’;
nlobj.Model.OutputFcn = ‘four_tankOutputFcn’;
SolverOptions.Algorithm = ‘sqp’;
%% validate the nonlinear MPC object with initial conditions
h0 = [12.44;13.17;4.73;4.986;0;0;0;0]; %[0.0033;920.86; 0.0104; 0.0085; 0.0118; 798];
u0 = [3.15;3.15];
validateFcns(nlobj, h0, u0);
four_tankStateFcnCT CODE:
function dhdt = four_tankStateFcnCT(h, u)
% Define system parameters
g = 981; % gravitational constant (m/s^2)
% Tank areas (in cm^2)
A1 = 28;
A2 = 32;
A3 = 28;
A4 = 32;
% Outlet areas (in cm^2)
a1 = 0.071;
a2 = 0.057;
a3 = 0.071;
a4 = 0.057;
% Flow distribution coefficients
gamma1 = 0.43;
gamma2 = 0.34;
% Pump constants (flow per voltage)
k1 = 3.14;
k2 = 3.29;
% State variables (water levels in each tank)
h1 = h(1);
h2 = h(2);
h3 = h(3);
h4 = h(4);
% Inputs (pump voltages)
v1 = u(1);
v2 = u(2);
dh1 = h1;
dh2 = h2;
dh3 = h3;
dh4 = h4;
dhdt = zeros(8,1);
% Equations from the journal
dhdt(1) = -a1/A1 * sqrt(2 * g * h1) + a3/A1 * sqrt(2 * g * h3) + (gamma1 * k1 * v1) / A1 + dh1;
dhdt(2) = -a2/A2 * sqrt(2 * g * h2) + a4/A2 * sqrt(2 * g * h4) + (gamma2 * k2 * v2) / A2 + dh2;
dhdt(3) = -a3/A3 * sqrt(2 * g * h3) + ((1 – gamma2) * k2 * v2) / A3 + dh3;
dhdt(4) = -a4/A4 * sqrt(2 * g * h4) + ((1 – gamma1) * k1 * v1) / A4 + dh4;
dhdt(5) = u(3);
dhdt(6) = u(4);
dhdt(7) = u(5);
dhdt(8) = u(6);
four_tankStateFcnDT CODE:
function hk1 = four_tankStateFcnDT(hk,uk)
hstep = 1;
hk1 = hk(:);
Nsteps = 2; % Number of integration time steps for Euler method
uk1 = [uk(:);0;0;0;0]; % The manipulated input + white noise of size 2
for i = 1:Nsteps
hk1 = hk1 + hstep*four_tankStateFcnCT(hk1,uk1);
end
four_tankMeasFcn CODE:
function y = four_tankMeasFcn(h)
y = [h(1) ;
h(2)] ;
four_tankOutputFcn CODE:
function y = four_tankOutputFcn(h,u)
y = [h(1) ;
h(2)] ;I got this error "Nonlinear constraint function is undefined at initial point. Fmincon cannot continue." when i ran a simulation to remove offset using extended kalman filter "EKF" in quadruple system. The target is to control level of water in the lower tank h1 and h2 by manipulating v1 and v2. check below for the code;
NMPC CODE:
clc, clear all
%% Simulink Model
% To run this example, Simulink(R) is required.
if ~mpcchecktoolboxinstalled(‘simulink’)
disp(‘Simulink is required to run this example.’)
return
end
%%initialize NMPC object and set properties
nx = 8;
ny = 2;
%nu = 2;
%’UD’, [5,6,7,8,9,10]
nlobj = nlmpc(nx, ny, ‘MV’, [1,2], ‘UD’, [3,4,5,6]);
%The prediction model sample time is the same as the controller sample time
Ts = 3; %Ts = 2
nlobj.Ts = Ts;
%Prediction and control horizon
nlobj.PredictionHorizon = 20;
nlobj.ControlHorizon = [1];
%weights on output and manipulated variables
nlobj.Weights.OutputVariables = [1000,1000]; %0.1
nlobj.Weights.ManipulatedVariables = [10,10]; %0.05;
%nlobj.Weights.ManipulatedVariablesRate = [10,10];
%constraints on manipulated variables
nlobj.MV(1).RateMin = -1;
nlobj.MV(2).RateMin = -1;
nlobj.MV(1).RateMax = 1;
nlobj.Mv(2).RateMax = 1;
nlobj.MV(1).Min = 2.7;
nlobj.MV(2).Min = 2.7;
nlobj.MV(1).Max = 3.3;
nlobj.MV(1).Max = 3.3;
%constraint on output variables to keep them within reasonable bounds
nlobj.OV(1).Min = 11.16;
nlobj.OV(2).Min = 11.43;
%nlobj.OV(3).Min = 2.5;
%nlobj.OV(4).Min = 2.5;
nlobj.OV(1).Max = 13.64;
nlobj.OV(2).Max = 13.97;
%nlobj.OV(3).Max = 8;
%nlobj.OV(4).Max = 8;
%% specify the nonlinear state and output functions
nlobj.Model.StateFcn = ‘four_tankStateFcnCT’;
nlobj.Model.OutputFcn = ‘four_tankOutputFcn’;
SolverOptions.Algorithm = ‘sqp’;
%% validate the nonlinear MPC object with initial conditions
h0 = [12.44;13.17;4.73;4.986;0;0;0;0]; %[0.0033;920.86; 0.0104; 0.0085; 0.0118; 798];
u0 = [3.15;3.15];
validateFcns(nlobj, h0, u0);
four_tankStateFcnCT CODE:
function dhdt = four_tankStateFcnCT(h, u)
% Define system parameters
g = 981; % gravitational constant (m/s^2)
% Tank areas (in cm^2)
A1 = 28;
A2 = 32;
A3 = 28;
A4 = 32;
% Outlet areas (in cm^2)
a1 = 0.071;
a2 = 0.057;
a3 = 0.071;
a4 = 0.057;
% Flow distribution coefficients
gamma1 = 0.43;
gamma2 = 0.34;
% Pump constants (flow per voltage)
k1 = 3.14;
k2 = 3.29;
% State variables (water levels in each tank)
h1 = h(1);
h2 = h(2);
h3 = h(3);
h4 = h(4);
% Inputs (pump voltages)
v1 = u(1);
v2 = u(2);
dh1 = h1;
dh2 = h2;
dh3 = h3;
dh4 = h4;
dhdt = zeros(8,1);
% Equations from the journal
dhdt(1) = -a1/A1 * sqrt(2 * g * h1) + a3/A1 * sqrt(2 * g * h3) + (gamma1 * k1 * v1) / A1 + dh1;
dhdt(2) = -a2/A2 * sqrt(2 * g * h2) + a4/A2 * sqrt(2 * g * h4) + (gamma2 * k2 * v2) / A2 + dh2;
dhdt(3) = -a3/A3 * sqrt(2 * g * h3) + ((1 – gamma2) * k2 * v2) / A3 + dh3;
dhdt(4) = -a4/A4 * sqrt(2 * g * h4) + ((1 – gamma1) * k1 * v1) / A4 + dh4;
dhdt(5) = u(3);
dhdt(6) = u(4);
dhdt(7) = u(5);
dhdt(8) = u(6);
four_tankStateFcnDT CODE:
function hk1 = four_tankStateFcnDT(hk,uk)
hstep = 1;
hk1 = hk(:);
Nsteps = 2; % Number of integration time steps for Euler method
uk1 = [uk(:);0;0;0;0]; % The manipulated input + white noise of size 2
for i = 1:Nsteps
hk1 = hk1 + hstep*four_tankStateFcnCT(hk1,uk1);
end
four_tankMeasFcn CODE:
function y = four_tankMeasFcn(h)
y = [h(1) ;
h(2)] ;
four_tankOutputFcn CODE:
function y = four_tankOutputFcn(h,u)
y = [h(1) ;
h(2)] ; I got this error "Nonlinear constraint function is undefined at initial point. Fmincon cannot continue." when i ran a simulation to remove offset using extended kalman filter "EKF" in quadruple system. The target is to control level of water in the lower tank h1 and h2 by manipulating v1 and v2. check below for the code;
NMPC CODE:
clc, clear all
%% Simulink Model
% To run this example, Simulink(R) is required.
if ~mpcchecktoolboxinstalled(‘simulink’)
disp(‘Simulink is required to run this example.’)
return
end
%%initialize NMPC object and set properties
nx = 8;
ny = 2;
%nu = 2;
%’UD’, [5,6,7,8,9,10]
nlobj = nlmpc(nx, ny, ‘MV’, [1,2], ‘UD’, [3,4,5,6]);
%The prediction model sample time is the same as the controller sample time
Ts = 3; %Ts = 2
nlobj.Ts = Ts;
%Prediction and control horizon
nlobj.PredictionHorizon = 20;
nlobj.ControlHorizon = [1];
%weights on output and manipulated variables
nlobj.Weights.OutputVariables = [1000,1000]; %0.1
nlobj.Weights.ManipulatedVariables = [10,10]; %0.05;
%nlobj.Weights.ManipulatedVariablesRate = [10,10];
%constraints on manipulated variables
nlobj.MV(1).RateMin = -1;
nlobj.MV(2).RateMin = -1;
nlobj.MV(1).RateMax = 1;
nlobj.Mv(2).RateMax = 1;
nlobj.MV(1).Min = 2.7;
nlobj.MV(2).Min = 2.7;
nlobj.MV(1).Max = 3.3;
nlobj.MV(1).Max = 3.3;
%constraint on output variables to keep them within reasonable bounds
nlobj.OV(1).Min = 11.16;
nlobj.OV(2).Min = 11.43;
%nlobj.OV(3).Min = 2.5;
%nlobj.OV(4).Min = 2.5;
nlobj.OV(1).Max = 13.64;
nlobj.OV(2).Max = 13.97;
%nlobj.OV(3).Max = 8;
%nlobj.OV(4).Max = 8;
%% specify the nonlinear state and output functions
nlobj.Model.StateFcn = ‘four_tankStateFcnCT’;
nlobj.Model.OutputFcn = ‘four_tankOutputFcn’;
SolverOptions.Algorithm = ‘sqp’;
%% validate the nonlinear MPC object with initial conditions
h0 = [12.44;13.17;4.73;4.986;0;0;0;0]; %[0.0033;920.86; 0.0104; 0.0085; 0.0118; 798];
u0 = [3.15;3.15];
validateFcns(nlobj, h0, u0);
four_tankStateFcnCT CODE:
function dhdt = four_tankStateFcnCT(h, u)
% Define system parameters
g = 981; % gravitational constant (m/s^2)
% Tank areas (in cm^2)
A1 = 28;
A2 = 32;
A3 = 28;
A4 = 32;
% Outlet areas (in cm^2)
a1 = 0.071;
a2 = 0.057;
a3 = 0.071;
a4 = 0.057;
% Flow distribution coefficients
gamma1 = 0.43;
gamma2 = 0.34;
% Pump constants (flow per voltage)
k1 = 3.14;
k2 = 3.29;
% State variables (water levels in each tank)
h1 = h(1);
h2 = h(2);
h3 = h(3);
h4 = h(4);
% Inputs (pump voltages)
v1 = u(1);
v2 = u(2);
dh1 = h1;
dh2 = h2;
dh3 = h3;
dh4 = h4;
dhdt = zeros(8,1);
% Equations from the journal
dhdt(1) = -a1/A1 * sqrt(2 * g * h1) + a3/A1 * sqrt(2 * g * h3) + (gamma1 * k1 * v1) / A1 + dh1;
dhdt(2) = -a2/A2 * sqrt(2 * g * h2) + a4/A2 * sqrt(2 * g * h4) + (gamma2 * k2 * v2) / A2 + dh2;
dhdt(3) = -a3/A3 * sqrt(2 * g * h3) + ((1 – gamma2) * k2 * v2) / A3 + dh3;
dhdt(4) = -a4/A4 * sqrt(2 * g * h4) + ((1 – gamma1) * k1 * v1) / A4 + dh4;
dhdt(5) = u(3);
dhdt(6) = u(4);
dhdt(7) = u(5);
dhdt(8) = u(6);
four_tankStateFcnDT CODE:
function hk1 = four_tankStateFcnDT(hk,uk)
hstep = 1;
hk1 = hk(:);
Nsteps = 2; % Number of integration time steps for Euler method
uk1 = [uk(:);0;0;0;0]; % The manipulated input + white noise of size 2
for i = 1:Nsteps
hk1 = hk1 + hstep*four_tankStateFcnCT(hk1,uk1);
end
four_tankMeasFcn CODE:
function y = four_tankMeasFcn(h)
y = [h(1) ;
h(2)] ;
four_tankOutputFcn CODE:
function y = four_tankOutputFcn(h,u)
y = [h(1) ;
h(2)] ; optimization, fmincon MATLAB Answers — New Questions
Initfcn callback wont update during the sensitivity analysis of my model
Hello everyone,
I’ve come across a strange problem concerning the sensitivity analysis tool and the initialization callback of my Simulink model. The initfcn callback uses some of the parameters in the parameter set of the sensitivity analysis session. When I run the sensitivity analysis the callback doesn’t see that the parameters are changing, it uses the same values (the default values in the base workspace) for each iteration.
OCVmine, OCVmaxe, lrStarte, lrEnde, me, pOCVmide are the variables in the base workspace that are being varied in the sensitivity analysis and this is my initfcn callback:
[SoCe, Vse] = pwp(OCVmine, OCVmaxe, lrStarte, lrEnde, me, pOCVmide);
set_param([gcs ‘/Battery/Cell 1’], ‘SoC’, ‘SoCe’, ‘OCV’, ‘Vse’);
[~, ix] = min(abs(SoCe – lrEnde/100));
Vinitiale = Vse(ix);
The variables are actually changing because the blocks in my model that use them see that they are changing, it’s only the callback that doesn’t seem to notice.
The top window shows the various samples of the sensitivity analysis session being evaluated, while the bottom window shows the baseworkspace.
Does anyone have any clue what may be causing this problem?
Thank you and enjoy your day.Hello everyone,
I’ve come across a strange problem concerning the sensitivity analysis tool and the initialization callback of my Simulink model. The initfcn callback uses some of the parameters in the parameter set of the sensitivity analysis session. When I run the sensitivity analysis the callback doesn’t see that the parameters are changing, it uses the same values (the default values in the base workspace) for each iteration.
OCVmine, OCVmaxe, lrStarte, lrEnde, me, pOCVmide are the variables in the base workspace that are being varied in the sensitivity analysis and this is my initfcn callback:
[SoCe, Vse] = pwp(OCVmine, OCVmaxe, lrStarte, lrEnde, me, pOCVmide);
set_param([gcs ‘/Battery/Cell 1’], ‘SoC’, ‘SoCe’, ‘OCV’, ‘Vse’);
[~, ix] = min(abs(SoCe – lrEnde/100));
Vinitiale = Vse(ix);
The variables are actually changing because the blocks in my model that use them see that they are changing, it’s only the callback that doesn’t seem to notice.
The top window shows the various samples of the sensitivity analysis session being evaluated, while the bottom window shows the baseworkspace.
Does anyone have any clue what may be causing this problem?
Thank you and enjoy your day. Hello everyone,
I’ve come across a strange problem concerning the sensitivity analysis tool and the initialization callback of my Simulink model. The initfcn callback uses some of the parameters in the parameter set of the sensitivity analysis session. When I run the sensitivity analysis the callback doesn’t see that the parameters are changing, it uses the same values (the default values in the base workspace) for each iteration.
OCVmine, OCVmaxe, lrStarte, lrEnde, me, pOCVmide are the variables in the base workspace that are being varied in the sensitivity analysis and this is my initfcn callback:
[SoCe, Vse] = pwp(OCVmine, OCVmaxe, lrStarte, lrEnde, me, pOCVmide);
set_param([gcs ‘/Battery/Cell 1’], ‘SoC’, ‘SoCe’, ‘OCV’, ‘Vse’);
[~, ix] = min(abs(SoCe – lrEnde/100));
Vinitiale = Vse(ix);
The variables are actually changing because the blocks in my model that use them see that they are changing, it’s only the callback that doesn’t seem to notice.
The top window shows the various samples of the sensitivity analysis session being evaluated, while the bottom window shows the baseworkspace.
Does anyone have any clue what may be causing this problem?
Thank you and enjoy your day. initfcn, sensitivity analysis MATLAB Answers — New Questions
Microsoft office Outlook while testing the settings
The same time as well and your family are doing well and your family
The same time as well and your family are doing well and your family Read More
[Azure DevOps] Failed to copy files for a specific release pipeline
Good morning everyone,
I have a problem in a specific pipeline, which must copy a file to a remote destination and I get an error:
2024-10-01T11:59:14.7214740Z Found 1 files to copy to the remote machine.
2024-10-01T11:59:14.7215725Z Copying file /Data_Build_Deploy/agente1/_work/r67/a/WSConsultaPoliza.war to /app/apache-tomcat-8.0.21/webapps/WSConsultaPoliza.war on remote machine.
2024-10-01T11:59:14.7312734Z ##[error]Failed to copy /Data_Build_Deploy/agente1/_work/r67/a/WSConsultaPoliza.war. Error: fastPut: Permission denied Local: /Data_Build_Deploy/agente1/_work/r67/a/WSConsultaPoliza.war Remote: /app/apache-tomcat-8.0.21/webapps/WSConsultaPoliza.war
at fmtError (/Data_Build_Deploy/agente1/_work/_tasks/CopyFilesOverSSH_67cec91b-0351-4c2f-8465-d74b3d2a2d96/0.246.1/node_modules/ssh2-sftp-client/src/utils.js:55:18)
at /Data_Build_Deploy/agente1/_work/_tasks/CopyFilesOverSSH_67cec91b-0351-4c2f-8465-d74b3d2a2d96/0.246.1/node_modules/ssh2-sftp-client/src/index.js:669:15
at cbfinal (/Data_Build_Deploy/agente1/_work/_tasks/CopyFilesOverSSH_67cec91b-0351-4c2f-8465-d74b3d2a2d96/0.246.1/node_modules/ssh2/lib/protocol/SFTP.js:2239:11)
at FSReqCallback.oncomplete (node:fs:192:23) {
code: 3,
custom: true
}
2024-10-01T11:59:14.7314728Z Completed copying 1 files to the remote machine.
2024-10-01T11:59:14.7315628Z ##[error]Failed to copy 1 files
This error occurs only with this release pipeline, I tried with other releases that copy to the same destination and this does not occur. I’ve even created a new Build and Release Pipeline again and I still get the same error.
What could I check to solve this?Thanks for your help
Good morning everyone,I have a problem in a specific pipeline, which must copy a file to a remote destination and I get an error:
2024-10-01T11:59:14.7214740Z Found 1 files to copy to the remote machine.
2024-10-01T11:59:14.7215725Z Copying file /Data_Build_Deploy/agente1/_work/r67/a/WSConsultaPoliza.war to /app/apache-tomcat-8.0.21/webapps/WSConsultaPoliza.war on remote machine.
2024-10-01T11:59:14.7312734Z ##[error]Failed to copy /Data_Build_Deploy/agente1/_work/r67/a/WSConsultaPoliza.war. Error: fastPut: Permission denied Local: /Data_Build_Deploy/agente1/_work/r67/a/WSConsultaPoliza.war Remote: /app/apache-tomcat-8.0.21/webapps/WSConsultaPoliza.war
at fmtError (/Data_Build_Deploy/agente1/_work/_tasks/CopyFilesOverSSH_67cec91b-0351-4c2f-8465-d74b3d2a2d96/0.246.1/node_modules/ssh2-sftp-client/src/utils.js:55:18)
at /Data_Build_Deploy/agente1/_work/_tasks/CopyFilesOverSSH_67cec91b-0351-4c2f-8465-d74b3d2a2d96/0.246.1/node_modules/ssh2-sftp-client/src/index.js:669:15
at cbfinal (/Data_Build_Deploy/agente1/_work/_tasks/CopyFilesOverSSH_67cec91b-0351-4c2f-8465-d74b3d2a2d96/0.246.1/node_modules/ssh2/lib/protocol/SFTP.js:2239:11)
at FSReqCallback.oncomplete (node:fs:192:23) {
code: 3,
custom: true
}
2024-10-01T11:59:14.7314728Z Completed copying 1 files to the remote machine.
2024-10-01T11:59:14.7315628Z ##[error]Failed to copy 1 files This error occurs only with this release pipeline, I tried with other releases that copy to the same destination and this does not occur. I’ve even created a new Build and Release Pipeline again and I still get the same error.What could I check to solve this?Thanks for your help Read More
auto-fill preset content (not sure if the labels are right)
I’m looking to use Excel spreadsheets as templates for reports. Unfortunately one thing has eluded me. Lets say I have a cell named ‘Hoover building, third floor, East wing’ I select it, fill in the information associated with that part of that floor in that building, and as soon as I start editing the cell a new one that says the same thing is automatically inserted below making it so that no matter how many different notes I need for the ‘Hoover building, third floor, East wing’ I always have the template notes ready because they just pop into existence.
I’m looking to use Excel spreadsheets as templates for reports. Unfortunately one thing has eluded me. Lets say I have a cell named ‘Hoover building, third floor, East wing’ I select it, fill in the information associated with that part of that floor in that building, and as soon as I start editing the cell a new one that says the same thing is automatically inserted below making it so that no matter how many different notes I need for the ‘Hoover building, third floor, East wing’ I always have the template notes ready because they just pop into existence. Read More