Tag Archives: matlab
How can I analyze the sum and product together in a code?
Hello,
I have just started to learn matlab and tried to solve the following equations:
where,
and the values of alpha(j) will be retrieved from an excel file containing 10 values of it.
Can someone let me know the procedure?
Thank youHello,
I have just started to learn matlab and tried to solve the following equations:
where,
and the values of alpha(j) will be retrieved from an excel file containing 10 values of it.
Can someone let me know the procedure?
Thank you Hello,
I have just started to learn matlab and tried to solve the following equations:
where,
and the values of alpha(j) will be retrieved from an excel file containing 10 values of it.
Can someone let me know the procedure?
Thank you programming, matlab, equation, sum MATLAB Answers — New Questions
Mean Value Analysis for Single Class Customers
Hello everyone,
I have a closed queue formulation where I require to do mean value analysis for single class of customers for single node, multiple nodes, infinite nodes and load dependent node. I am attaching the formula. Can you kindly help me in getting the answer.
inputs: N, K, m_i, p_ij, mu_i, mu_i(j)
Thank you for your help.
With regards,Hello everyone,
I have a closed queue formulation where I require to do mean value analysis for single class of customers for single node, multiple nodes, infinite nodes and load dependent node. I am attaching the formula. Can you kindly help me in getting the answer.
inputs: N, K, m_i, p_ij, mu_i, mu_i(j)
Thank you for your help.
With regards, Hello everyone,
I have a closed queue formulation where I require to do mean value analysis for single class of customers for single node, multiple nodes, infinite nodes and load dependent node. I am attaching the formula. Can you kindly help me in getting the answer.
inputs: N, K, m_i, p_ij, mu_i, mu_i(j)
Thank you for your help.
With regards, mean value analysis, queueing theory MATLAB Answers — New Questions
I want to change the parameters of the Synchronous Machine Model 1.0 according to the rpm.
I am using the Synchronous Machine Model 1.0 in Simulink Simscape.
I want to model a generator and need to change the parameters of the Synchronous Machine Model 1.0 according to the rpm. Currently, I have declared the parameters in the workspace and am importing them into the model.
I have the relationship between rpm and the parameters, I want to change the parameters at every step. How can I do this?I am using the Synchronous Machine Model 1.0 in Simulink Simscape.
I want to model a generator and need to change the parameters of the Synchronous Machine Model 1.0 according to the rpm. Currently, I have declared the parameters in the workspace and am importing them into the model.
I have the relationship between rpm and the parameters, I want to change the parameters at every step. How can I do this? I am using the Synchronous Machine Model 1.0 in Simulink Simscape.
I want to model a generator and need to change the parameters of the Synchronous Machine Model 1.0 according to the rpm. Currently, I have declared the parameters in the workspace and am importing them into the model.
I have the relationship between rpm and the parameters, I want to change the parameters at every step. How can I do this? simulink, simscape, workspace MATLAB Answers — New Questions
MemMap.h file does not contain content for Calprm and Var memory segments that were present in .c source code file
Hello,
I am using Matlab R2023b. I have created a Simulink model and generated AUTOSAR compliant C code. In my Simulink model, I created SwAddrMethods named CAL, CODE and VAR. The CAL method is for Calprm memory section, CODE is for Code memory section and VAR is for Var memory section.
In my generated .c source code and .h header files, I see the #defines for each SwAddrMethod. Some excerpts from my .c code below:
.
.
/* Please see snapshots for source code and MemMap header file for reference. */
.
.
Same case is true for the .h header file. I can see instances of #defines for all 3 SwAddrMethods.
But, in the generated MemMap.h header file, I can only see reference to #ifdef PwrSteerOutPrcs_START_SEC_CODE
#undef PwrSteerOutPrcs_START_SEC_CODE and #ifdef PwrSteerOutPrcs_STOP_SEC_CODE
#undef PwrSteerOutPrcs_STOP_SEC_CODE.
I do not notice the START_SEC_CAL, STOP_SEC_CAL and START_SEC_VAR, STOP_SEC_VAR are being generated.
.
.
/* Please see snapshots for source code and MemMap header file for reference. */
.
.
Q1. What can cause the #defines for CAL and VAR to not be defined in MemMap.h? Is this soem setting I can correct in Autosar Component Viewer app / Simulink Model Settings? Or is it a bug in Matlab R2023b release?
Attached are snapshot #1 of the 1 instrumented signal. Am I using the correct settings? I have noticed in some models that instead of ‘From signal object: Global’ , there is an ‘Auto’ option in the dropdown for ‘Mapped to’ (attached in snapshot #2). I do not get that option for ‘Auto’.
Q2. Is there a setting I should change on my Model Settings / Autosar App to get the Auto dropdown option? Will that help resolve Q1? Or is this a bug in matlab R2023b. Please advise.
Any help is much appreciated! Thank you!Hello,
I am using Matlab R2023b. I have created a Simulink model and generated AUTOSAR compliant C code. In my Simulink model, I created SwAddrMethods named CAL, CODE and VAR. The CAL method is for Calprm memory section, CODE is for Code memory section and VAR is for Var memory section.
In my generated .c source code and .h header files, I see the #defines for each SwAddrMethod. Some excerpts from my .c code below:
.
.
/* Please see snapshots for source code and MemMap header file for reference. */
.
.
Same case is true for the .h header file. I can see instances of #defines for all 3 SwAddrMethods.
But, in the generated MemMap.h header file, I can only see reference to #ifdef PwrSteerOutPrcs_START_SEC_CODE
#undef PwrSteerOutPrcs_START_SEC_CODE and #ifdef PwrSteerOutPrcs_STOP_SEC_CODE
#undef PwrSteerOutPrcs_STOP_SEC_CODE.
I do not notice the START_SEC_CAL, STOP_SEC_CAL and START_SEC_VAR, STOP_SEC_VAR are being generated.
.
.
/* Please see snapshots for source code and MemMap header file for reference. */
.
.
Q1. What can cause the #defines for CAL and VAR to not be defined in MemMap.h? Is this soem setting I can correct in Autosar Component Viewer app / Simulink Model Settings? Or is it a bug in Matlab R2023b release?
Attached are snapshot #1 of the 1 instrumented signal. Am I using the correct settings? I have noticed in some models that instead of ‘From signal object: Global’ , there is an ‘Auto’ option in the dropdown for ‘Mapped to’ (attached in snapshot #2). I do not get that option for ‘Auto’.
Q2. Is there a setting I should change on my Model Settings / Autosar App to get the Auto dropdown option? Will that help resolve Q1? Or is this a bug in matlab R2023b. Please advise.
Any help is much appreciated! Thank you! Hello,
I am using Matlab R2023b. I have created a Simulink model and generated AUTOSAR compliant C code. In my Simulink model, I created SwAddrMethods named CAL, CODE and VAR. The CAL method is for Calprm memory section, CODE is for Code memory section and VAR is for Var memory section.
In my generated .c source code and .h header files, I see the #defines for each SwAddrMethod. Some excerpts from my .c code below:
.
.
/* Please see snapshots for source code and MemMap header file for reference. */
.
.
Same case is true for the .h header file. I can see instances of #defines for all 3 SwAddrMethods.
But, in the generated MemMap.h header file, I can only see reference to #ifdef PwrSteerOutPrcs_START_SEC_CODE
#undef PwrSteerOutPrcs_START_SEC_CODE and #ifdef PwrSteerOutPrcs_STOP_SEC_CODE
#undef PwrSteerOutPrcs_STOP_SEC_CODE.
I do not notice the START_SEC_CAL, STOP_SEC_CAL and START_SEC_VAR, STOP_SEC_VAR are being generated.
.
.
/* Please see snapshots for source code and MemMap header file for reference. */
.
.
Q1. What can cause the #defines for CAL and VAR to not be defined in MemMap.h? Is this soem setting I can correct in Autosar Component Viewer app / Simulink Model Settings? Or is it a bug in Matlab R2023b release?
Attached are snapshot #1 of the 1 instrumented signal. Am I using the correct settings? I have noticed in some models that instead of ‘From signal object: Global’ , there is an ‘Auto’ option in the dropdown for ‘Mapped to’ (attached in snapshot #2). I do not get that option for ‘Auto’.
Q2. Is there a setting I should change on my Model Settings / Autosar App to get the Auto dropdown option? Will that help resolve Q1? Or is this a bug in matlab R2023b. Please advise.
Any help is much appreciated! Thank you! memorymap, memmap.h, swaddrmethods, autosar dictionary, autosar code generation MATLAB Answers — New Questions
Create a table with 2 header lines followed by numeric data
header line 1 = string
header line 2 = string
line 3:end = numeric data
How do I create a table with two header lines followed by the numeric data?
I have been using table(numeric data, ‘VariableNames’, header line 1) but cannot find a way to have two header lines before the numeric data begins.
Any help would be much appreciated.header line 1 = string
header line 2 = string
line 3:end = numeric data
How do I create a table with two header lines followed by the numeric data?
I have been using table(numeric data, ‘VariableNames’, header line 1) but cannot find a way to have two header lines before the numeric data begins.
Any help would be much appreciated. header line 1 = string
header line 2 = string
line 3:end = numeric data
How do I create a table with two header lines followed by the numeric data?
I have been using table(numeric data, ‘VariableNames’, header line 1) but cannot find a way to have two header lines before the numeric data begins.
Any help would be much appreciated. table MATLAB Answers — New Questions
Matlab GUI Standalone Applications for Arduino Hardware
I worked on a simple GUI that does nothing but read an analog pin and send some commands on digital pins (I have some buttons in the GUI that do this) on my arduino board. Everything works as it should when I run GUI through MatLab. I tried to deploy this GUI also for my colleagues who do not use Matlab following the indications from here: Create Standalone Applications for Arduino Hardware – MATLAB & Simulink (mathworks.com).
I downloaded the Arduino CLI, unzipped it, then with the commands "arduino-cli core install arduino:avr@xxx" I installed all the boards. The problem is that when I try to connect to my arduino board, I select the correct COM port, board type, and the path to the Arduino CLI, regardless of which path I choose, it doesn’t work.I worked on a simple GUI that does nothing but read an analog pin and send some commands on digital pins (I have some buttons in the GUI that do this) on my arduino board. Everything works as it should when I run GUI through MatLab. I tried to deploy this GUI also for my colleagues who do not use Matlab following the indications from here: Create Standalone Applications for Arduino Hardware – MATLAB & Simulink (mathworks.com).
I downloaded the Arduino CLI, unzipped it, then with the commands "arduino-cli core install arduino:avr@xxx" I installed all the boards. The problem is that when I try to connect to my arduino board, I select the correct COM port, board type, and the path to the Arduino CLI, regardless of which path I choose, it doesn’t work. I worked on a simple GUI that does nothing but read an analog pin and send some commands on digital pins (I have some buttons in the GUI that do this) on my arduino board. Everything works as it should when I run GUI through MatLab. I tried to deploy this GUI also for my colleagues who do not use Matlab following the indications from here: Create Standalone Applications for Arduino Hardware – MATLAB & Simulink (mathworks.com).
I downloaded the Arduino CLI, unzipped it, then with the commands "arduino-cli core install arduino:avr@xxx" I installed all the boards. The problem is that when I try to connect to my arduino board, I select the correct COM port, board type, and the path to the Arduino CLI, regardless of which path I choose, it doesn’t work. matlab, gui, matlab gui, arduino, deploytool MATLAB Answers — New Questions
Why can’t this example of “Signal Source Separation Using W-Net Architecture” be opened in MATLAB?
When i try to run the example of "Signal Source Separation Using W-Net Architecture" on MATLAB, it showed "Error: "Error saving to local data stream." when communicating with websave (line 107) 5URL ‘https://ssd.mathworks.com/supportfiles/SPT/data/fetal-ecg-source-separation-testData,zip’.
error matlab,internal.examples.downloadsupportFile(line 48)localfile =websave(localfile,webFilePath);".
The code block :"Download the train and test data sets using the downloadSupportFile function. The data will be unzipped to the tempdir directory. If you want the data at a different location, change trainingDatasetFolder and testDatasetFolder to the desired locations " can’t run, and the detailed code is if trainNetworkFlag
% Download training data set
trainingDatasetZipFile = matlab.internal.examples.downloadSupportFile(‘SPT’,’data/fetal-ecg-source-separation-trainingData.zip’);
trainingDatasetFolder = fullfile(tempdir,’fetal-ecg-source-separation-trainingData’);
if ~exist(trainingDatasetFolder,’dir’)
unzip(trainingDatasetZipFile,trainingDatasetFolder);
end
end
% Download test data set
testDatasetZipFile = matlab.internal.examples.downloadSupportFile(‘SPT’,’data/fetal-ecg-source-separation-testData.zip’);
testDatasetFolder = fullfile(tempdir,’fetal-ecg-source-separation-testData’);
if ~exist(testDatasetFolder,’dir’)
unzip(testDatasetZipFile,testDatasetFolder);
end
Thank you very much for your answers!have a nice day!When i try to run the example of "Signal Source Separation Using W-Net Architecture" on MATLAB, it showed "Error: "Error saving to local data stream." when communicating with websave (line 107) 5URL ‘https://ssd.mathworks.com/supportfiles/SPT/data/fetal-ecg-source-separation-testData,zip’.
error matlab,internal.examples.downloadsupportFile(line 48)localfile =websave(localfile,webFilePath);".
The code block :"Download the train and test data sets using the downloadSupportFile function. The data will be unzipped to the tempdir directory. If you want the data at a different location, change trainingDatasetFolder and testDatasetFolder to the desired locations " can’t run, and the detailed code is if trainNetworkFlag
% Download training data set
trainingDatasetZipFile = matlab.internal.examples.downloadSupportFile(‘SPT’,’data/fetal-ecg-source-separation-trainingData.zip’);
trainingDatasetFolder = fullfile(tempdir,’fetal-ecg-source-separation-trainingData’);
if ~exist(trainingDatasetFolder,’dir’)
unzip(trainingDatasetZipFile,trainingDatasetFolder);
end
end
% Download test data set
testDatasetZipFile = matlab.internal.examples.downloadSupportFile(‘SPT’,’data/fetal-ecg-source-separation-testData.zip’);
testDatasetFolder = fullfile(tempdir,’fetal-ecg-source-separation-testData’);
if ~exist(testDatasetFolder,’dir’)
unzip(testDatasetZipFile,testDatasetFolder);
end
Thank you very much for your answers!have a nice day! When i try to run the example of "Signal Source Separation Using W-Net Architecture" on MATLAB, it showed "Error: "Error saving to local data stream." when communicating with websave (line 107) 5URL ‘https://ssd.mathworks.com/supportfiles/SPT/data/fetal-ecg-source-separation-testData,zip’.
error matlab,internal.examples.downloadsupportFile(line 48)localfile =websave(localfile,webFilePath);".
The code block :"Download the train and test data sets using the downloadSupportFile function. The data will be unzipped to the tempdir directory. If you want the data at a different location, change trainingDatasetFolder and testDatasetFolder to the desired locations " can’t run, and the detailed code is if trainNetworkFlag
% Download training data set
trainingDatasetZipFile = matlab.internal.examples.downloadSupportFile(‘SPT’,’data/fetal-ecg-source-separation-trainingData.zip’);
trainingDatasetFolder = fullfile(tempdir,’fetal-ecg-source-separation-trainingData’);
if ~exist(trainingDatasetFolder,’dir’)
unzip(trainingDatasetZipFile,trainingDatasetFolder);
end
end
% Download test data set
testDatasetZipFile = matlab.internal.examples.downloadSupportFile(‘SPT’,’data/fetal-ecg-source-separation-testData.zip’);
testDatasetFolder = fullfile(tempdir,’fetal-ecg-source-separation-testData’);
if ~exist(testDatasetFolder,’dir’)
unzip(testDatasetZipFile,testDatasetFolder);
end
Thank you very much for your answers!have a nice day! wnet, ecg signal, neural network, signal separate, matlab code MATLAB Answers — New Questions
Why does my GTX Titan Black GPU underperform in double precision calculations in MATLAB R2015a?
I experience unexpectedly slow performance of the GPU in double precision benchmarks.
I have a fast PC (Intel i7-4790 3.6GHz, 16GB of 1600MHz memory, Windows 7 64bit, and a nVidia GeForce GTX Titan Black GPU card, in PCIe 3.0×16 slot, with 850W power supply. I have downloaded the video drivers and CUDA toolkit and installed matlab Parallel Computing Toolbox:
>> gpuDeviceans =CUDADevice withproperties:Name: ‘GeForce GTX TITAN Black’Index: 1ComputeCapability: ‘3.5’SupportsDouble: 1DriverVersion: 7ToolkitVersion: 6.5000MaxThreadsPerBlock: 1024MaxShmemPerBlock: 49152MaxThreadBlockSize: [1024 1024 64]MaxGridSize: [2.1475e+09 65535 65535]SIMDWidth: 32TotalMemory: 6.4425e+09AvailableMemory: 6.2105e+09MultiprocessorCount: 15ClockRateKHz: 980000ComputeMode: ‘Default’GPUOverlapsTransfers: 1KernelExecutionTimeout: 1CanMapHostMemory: 1DeviceSupported: 1DeviceSelected: 1
I then downloaded the GPU benchmarking tool by by the MathWorks Parallel Computing Toolbox Team (version of Updated 05 Jan 2015), from http://www.mathworks.com/matlabcentral/fileexchange/34080-gpubenchand executed the “gpuBench”.
The results show that my GPU performs similarly to Quadro K6000 in single precision benchmarks (with deviations up to 40%, as expected: both the cards have the same no of CUDA cores but the memory bandwidth is higher for my Titan Black and the amount of memory is higher K6000)
However, the GeForce GTX Titan Black performs 4 times (!) slower than Quadro K6000 in the double precision benchmarks! This is unexpected for several reasons.A) both cards are fairly similar:Specification type K6000 / Titan BlackCUDA cores: 2880 / 2880Clock: 902MHz /889MHzMemory clock: 6 Gbps/ 7GbpsMemory bandwidth: 288GB/s / 336GB/s
B) There are benchmarking tests done by the MathWorksParallel Computing Toolbox Team shown in the file “Older benchmarks for GPUs” attached. From those results, a GPU very similar to mine, GeForce GTX Titan (anolder GPU with 2688 CUDA cores, 837MHz clock, 6Gbps memory clock and 288GB/s memory bandwidth) shows benchmarks very much similar to Quadro K6000:
Card DOUBLE SINGLE Benchmark MTimes,Backlash, FFT, MTimes,Backlash,FFTK6000 1092 421 160 3017 831 334GTX Titan 1106 352 150 2933 582 298My GPU 252 163 110 4221 994 409
These results indicate that my GPU card (GeForce GTX Titan Black) should be faster than or similar to the Quadro K6000. However, the performance in the double precision is terrible (4x slower).I experience unexpectedly slow performance of the GPU in double precision benchmarks.
I have a fast PC (Intel i7-4790 3.6GHz, 16GB of 1600MHz memory, Windows 7 64bit, and a nVidia GeForce GTX Titan Black GPU card, in PCIe 3.0×16 slot, with 850W power supply. I have downloaded the video drivers and CUDA toolkit and installed matlab Parallel Computing Toolbox:
>> gpuDeviceans =CUDADevice withproperties:Name: ‘GeForce GTX TITAN Black’Index: 1ComputeCapability: ‘3.5’SupportsDouble: 1DriverVersion: 7ToolkitVersion: 6.5000MaxThreadsPerBlock: 1024MaxShmemPerBlock: 49152MaxThreadBlockSize: [1024 1024 64]MaxGridSize: [2.1475e+09 65535 65535]SIMDWidth: 32TotalMemory: 6.4425e+09AvailableMemory: 6.2105e+09MultiprocessorCount: 15ClockRateKHz: 980000ComputeMode: ‘Default’GPUOverlapsTransfers: 1KernelExecutionTimeout: 1CanMapHostMemory: 1DeviceSupported: 1DeviceSelected: 1
I then downloaded the GPU benchmarking tool by by the MathWorks Parallel Computing Toolbox Team (version of Updated 05 Jan 2015), from http://www.mathworks.com/matlabcentral/fileexchange/34080-gpubenchand executed the “gpuBench”.
The results show that my GPU performs similarly to Quadro K6000 in single precision benchmarks (with deviations up to 40%, as expected: both the cards have the same no of CUDA cores but the memory bandwidth is higher for my Titan Black and the amount of memory is higher K6000)
However, the GeForce GTX Titan Black performs 4 times (!) slower than Quadro K6000 in the double precision benchmarks! This is unexpected for several reasons.A) both cards are fairly similar:Specification type K6000 / Titan BlackCUDA cores: 2880 / 2880Clock: 902MHz /889MHzMemory clock: 6 Gbps/ 7GbpsMemory bandwidth: 288GB/s / 336GB/s
B) There are benchmarking tests done by the MathWorksParallel Computing Toolbox Team shown in the file “Older benchmarks for GPUs” attached. From those results, a GPU very similar to mine, GeForce GTX Titan (anolder GPU with 2688 CUDA cores, 837MHz clock, 6Gbps memory clock and 288GB/s memory bandwidth) shows benchmarks very much similar to Quadro K6000:
Card DOUBLE SINGLE Benchmark MTimes,Backlash, FFT, MTimes,Backlash,FFTK6000 1092 421 160 3017 831 334GTX Titan 1106 352 150 2933 582 298My GPU 252 163 110 4221 994 409
These results indicate that my GPU card (GeForce GTX Titan Black) should be faster than or similar to the Quadro K6000. However, the performance in the double precision is terrible (4x slower). I experience unexpectedly slow performance of the GPU in double precision benchmarks.
I have a fast PC (Intel i7-4790 3.6GHz, 16GB of 1600MHz memory, Windows 7 64bit, and a nVidia GeForce GTX Titan Black GPU card, in PCIe 3.0×16 slot, with 850W power supply. I have downloaded the video drivers and CUDA toolkit and installed matlab Parallel Computing Toolbox:
>> gpuDeviceans =CUDADevice withproperties:Name: ‘GeForce GTX TITAN Black’Index: 1ComputeCapability: ‘3.5’SupportsDouble: 1DriverVersion: 7ToolkitVersion: 6.5000MaxThreadsPerBlock: 1024MaxShmemPerBlock: 49152MaxThreadBlockSize: [1024 1024 64]MaxGridSize: [2.1475e+09 65535 65535]SIMDWidth: 32TotalMemory: 6.4425e+09AvailableMemory: 6.2105e+09MultiprocessorCount: 15ClockRateKHz: 980000ComputeMode: ‘Default’GPUOverlapsTransfers: 1KernelExecutionTimeout: 1CanMapHostMemory: 1DeviceSupported: 1DeviceSelected: 1
I then downloaded the GPU benchmarking tool by by the MathWorks Parallel Computing Toolbox Team (version of Updated 05 Jan 2015), from http://www.mathworks.com/matlabcentral/fileexchange/34080-gpubenchand executed the “gpuBench”.
The results show that my GPU performs similarly to Quadro K6000 in single precision benchmarks (with deviations up to 40%, as expected: both the cards have the same no of CUDA cores but the memory bandwidth is higher for my Titan Black and the amount of memory is higher K6000)
However, the GeForce GTX Titan Black performs 4 times (!) slower than Quadro K6000 in the double precision benchmarks! This is unexpected for several reasons.A) both cards are fairly similar:Specification type K6000 / Titan BlackCUDA cores: 2880 / 2880Clock: 902MHz /889MHzMemory clock: 6 Gbps/ 7GbpsMemory bandwidth: 288GB/s / 336GB/s
B) There are benchmarking tests done by the MathWorksParallel Computing Toolbox Team shown in the file “Older benchmarks for GPUs” attached. From those results, a GPU very similar to mine, GeForce GTX Titan (anolder GPU with 2688 CUDA cores, 837MHz clock, 6Gbps memory clock and 288GB/s memory bandwidth) shows benchmarks very much similar to Quadro K6000:
Card DOUBLE SINGLE Benchmark MTimes,Backlash, FFT, MTimes,Backlash,FFTK6000 1092 421 160 3017 831 334GTX Titan 1106 352 150 2933 582 298My GPU 252 163 110 4221 994 409
These results indicate that my GPU card (GeForce GTX Titan Black) should be faster than or similar to the Quadro K6000. However, the performance in the double precision is terrible (4x slower). gpu, slow, slower MATLAB Answers — New Questions
optimising hybrid energy design using genetic algorithm
i’m working on optimising a design of a hybrid PV/Wind energy system (with battery) using Genetic Algorithms ,and based on a research paper i have been able to code the following :
% Solar PV Generator script
function solargen = solar(Areapv)
% Input:
% Areapv = total area of all PV modules, one of the variables to be optimized
% x = solar irradiance (data read from an Excel file)
x = xlsread(‘éclairement_tlemcen.xlsx’,’A1:A8784′);
effpv = 0.227; % efficiency of the PV module specified by manufacturer
% Output:
% solargen = power produced by the PV generator (kW)
% solargen = Areapv * effpv * Irrad * 0.001;
w = effpv * Areapv * 0.001;
solargen = w .* x;
end
wind turbine script
% Wind Generator script
function windgen = windpower(Areawt)
% Inputs:
% Areawt = total rotor swept area of all wind turbines used (m2)
% Areawt is one of the variables to be optimized
coeff_wt = 45/100; % coefficient of power of wind turbine
rho = 1.1839; % density of air (kg/m3) at 1 atm pres and 25 degC temp
vci = 2.01168; % wind turbine cut-in/min wind speed (m/s)
vrat = 13.8582; % wind turbine rated wind speed (m/s)
vco = 17.8816; % wind turbine cut-out/max wind speed (m/s)
% vact = actual wind speed (data read from an Excel file)
vact = xlsread(‘wind_speed_tlemcen.xlsx’,’A1:A8784′);
y = length(vact); % number of wind speed data points
% windgen = power produced by the wind generator (kW)
b = zeros(1, y); % preallocation of memory outside loop
windgen = b.’;
for a = 1:y
if ((vact(a) < vci)||(vact(a) > vco)) % wind speed less than cut-in or greater than cut-out
z = 0;
elseif ((vact(a) >= vci)&&(vact(a) < vrat)) % wind speed between cut-in and rated
z = 0.5 * coeff_wt * rho * Areawt * (vrat.^3) * ((vact(a).^3 – vci.^3)/(vrat.^3 – vci.^3)) * 0.001;
else % wind speed between rated and cut-out
z = 0.5 * coeff_wt * rho * Areawt * (vrat.^3) * 0.001;
end
windgen(a) = z;
end
end
battery script
% Battery System script
function [battpower,Pload] = battery(Areapv,Areawt,Capbatt)
% Inputs:
% Areapv = total area of all PV modules used (m2)
% Areawt = total rotor swept area of all wind turbines used (m2)
% Capbatt = total energy capacity of all batteries used (kWh)
% The three inputs are the variables to be optimized
% Pload = load demand (data read from an Excel file)
Pl = xlsread(‘charge_tlemcen.xlsx’,’A1:A8784′);
Pload = 0.001 * Pl; % load power in kW
eff_inv = 88/100; % efficiency of inverter
eff_batt_cha = 92/100; % efficiency of battery charging
eff_batt_disch = 100/100; % efficiency of battery discharging
Ppv = solar(Areapv); % generation from solar
Pwind = windpower(Areawt); % generation from wind
soc_max = 98/100; % maximum state of charge of battery
dod_max = 80/100; % maximum depth of discharge
y = length(Pload);
% preallocation of memory outside loop for some variables
c = zeros(1, y);
Pgen = c.’;
d = zeros(1, y);
soc = d.’;
e = zeros(1, y);
dod = e.’;
f = zeros(1, y);
Pdump = f.’;
g = zeros(1, y);
battpower = g.’;
h = zeros(1, y);
Pdef = h.’;
soc(1) = soc_max; % initial state of charge of battery
dod(1) = 1 – soc(1); % initial state of discharge of battery
for b = 1:y
Pgen(b) = Ppv(b) + Pwind(b);
soc(b) = soc(b) + (battpower(b)/(1000*Capbatt));
if Pgen(b) > (Pload(b)/eff_inv) % generation > load
if soc(b) < soc_max % battery not charged fully
battpower(b) = (Pgen(b) – (Pload(b)/eff_inv)) *eff_batt_cha; % battery charges, battpower is +ve
else
soc(b) >= soc_max; % battery charged to maximum
battpower(b) = 0; % no more charging
Pdump(b) = Pgen(b) – (Pload(b)/eff_inv);
% surplus power is dumped after battery charges to maximum
end
elseif Pgen(b) < (Pload(b)/eff_inv) % generation < load
if (dod(b)) < dod_max % battery not dicharged to maximum
battpower(b) = -((Pload(b)/eff_inv) – Pgen(b)) * eff_batt_disch; % battery discharges, battpower is -ve
else
dod(b) >= dod_max; % battery discharged to maximum
battpower(b) = 0; % no more discharging
Pdef(b) = Pload(b) – (Pgen(b) + ((1000 * Capbatt)* ((soc(b)-(1-dod_max))))* eff_inv);
% deficit power persists after battery discharged fully
end
else % Pgen(b) = (Pload(b)/eff_inv) i.e. generation = load
battpower(b) = 0; % No charging or discharging
end
end
end
LPSP script which is the non linear constraint script
function [LPSP_value,LPSP_eq] = LPSP(Areapv,Areawt,Capbatt)
eff_inv = 88/100; % efficiency of inverter
s = solar(Areapv); % call solar function
w = windpower(Areawt); % call wind function
Pg = s + w; % generation = solar + wind
[b,Pl] = battery(Areapv,Areawt,Capbatt); % call battery function
Pgen = sum(Pg); % total generation
Pload = sum(Pl); % total load
battp = sum(b); % total battery power
LPS = sum(Pdef);
LPSP_value = (LPS / Pload) – 0.05; % LPSP <= 0.05
LPSP_eq = [];
end
the cost script which is the objective function
% Total System Cost script
% The total system cost is the sum of the following costs:
% Capital/investment costs
% Operation and maintenance costs
% Replacement costs
% Salvage revenue (negative cost)
% The present value of the above cost components are found for each of the
% three main system components: solar pv generator, wind generator and
% battery system; all costs are then added to get the total system cost
% The total system cost is the objective function to be optimized by a
% genetic algorithm. The constraints of this function are the loss of power
% supply probability (defined in a separate function) and the input
% variables.
function system_cost = cost(Areapv,Areawt,Capbatt)
%————————————————————————-%
% Constraints
Areapv_max = 20 * 1.63; % 20 PV modules maximum (32.6 m2 max area)
Areapv(Areapv>Areapv_max) = Areapv_max;
Areapv_min = 10 * 1.63; % 10 PV modules minimum (16.3 m2 min area)
Areapv(Areapv<Areapv_min) = Areapv_min;
Areawt_max = 10 * pi * (0.85344.^2); % 10 wind turbines maximum
% (22.8821 m2 max area)
Areawt(Areawt>Areawt_max) = Areawt_max;
Areawt_min = 3 * pi * (0.85344.^2); % 3 wind turbines minimum
% (6.8646 m2 min area)
Areawt(Areawt<Areawt_min) = Areawt_min;
Capbatt_max = 20 * 1.68; % 20 battery units maximum (33.6 kWh max)
Capbatt(Capbatt>Capbatt_max) = Capbatt_max;
Capbatt_min = 10 * 1.68; % 10 battery units minimum (16.8 kWh min)
Capbatt(Capbatt<Capbatt_min) = Capbatt_min;
%————————————————————————-%
% Project lifetime
%proj_life = 25; % years
%————————————————————————-%
% Rates applicable
%int = 5/100; % interest rate that affects all costs
%infl = 3/100; % inflation rate that affects salvage costs
%inc = 4/100; % non-inflation rate at which non-salvage costs increase
%————————————————————————-%
% Solar specifications
cap_pv = 300/1.63; % capital cost of PV module (184.0491 UK pounds/m2)
oandm_pv = 7.5/1.63; % o & m cost of PV module (4.6012 UK pounds/m2/yr)
sal_pv = 60/1.63; % salvage revenue of PV module (36.8098 UK pounds/m2)
%life_pv = 25; % lifetime of PV module (years)
%rep_pv = (proj_life / life_pv) – 1; % number of replacements in project (0)
%————————————————————————-%
% Wind specifications
cap_wt = 1125/(pi*(0.85344.^2)); % capital cost of turbine
% (491.6507 UK pounds/m2)
oandm_wt = 168.75/(pi*(0.85344.^2)); % o & m cost of turbine
% (73.7476 UK pounds/m2/yr)
sal_wt = 225/(pi*(0.85344.^2)); % salvage revenue of turbine
% (98.3301 UK pounds/m2)
%life_wt = 12.5; % lifetime of turbine (years)
%rep_wt = (proj_life / life_wt) – 1; % number of replacements in project (1)
%————————————————————————-%
% Battery specifications
cap_batt = 364/1.68; % capital cost of battery (216.6667 UK pounds/kWh)
oandm_batt = 3.64/1.68; % o & m cost of battery (2.1667 UK pounds/kWh/yr)
sal_batt = 36.4/1.68; % salvage revenue of battery (21.6667 UK pounds/kWh)
%life_batt = 2.5; % lifetime of battery (years)
%rep_batt = (proj_life / life_batt) – 1; % number of replacements in project;
% (9)
%————————————————————————-%
% Useful factors for net present value
%fac1 = (1+inc)/(1+int); % 0.9905
%fac2 = (1+infl)/(1+int); % 0.9810
%factor1a = symsum(fac1.^((k-1)*life_wt),k,1,rep_wt);
factor1a = 1; % summation of fac1^(k-1)*life_wt) for turbine replacements
%factor1b = symsum(fac1.^((k-1)*life_batt),k,1,rep_batt);
factor1b = 8.1943; % summation of fac1.^((k-1)*life_batt) for battery
% replacements
%factor2 = symsum(fac1.^k,k,1,proj_life);
factor2 = 22.1282; % summation of fac1^k for project life
% factor2 = fac1 + (fac1.^2) + (fac1.^3) + … + (fac1.^25)
%factor3a = ((1+infl).^proj_life)/((1+int).^proj_life);
factor3a = 0.6183;
%factor3b = symsum(fac2.^(x*life_wt),x,1,rep_wt);
factor3b = 0.7863; % summation of fac2^(x*life_wt) for turbine life
%factor3c = symsum(fac2.^(x*life_batt),x,1,rep_batt);
factor3c = 7.1315; % summation of fac2^(x*life_batt) for battery life
%————————————————————————-%
% Capital costs and replacement costs
% Solar
pv_caprep = cap_pv * Areapv;
pv_caprep_npv = pv_caprep;
const_pv1 = pv_caprep_npv / Areapv;
% Wind
windg_caprep = cap_wt * Areawt;
windg_caprep_npv = windg_caprep * factor1a;
const_wt1 = windg_caprep_npv / Areawt;
% Battery
batt_caprep = cap_batt * Capbatt;
batt_caprep_npv = batt_caprep * factor1b;
const_batt1 = batt_caprep_npv / Capbatt;
%————————————————————————-%
% Operation and maintenance costs
% Solar
pv_oandm = oandm_pv * Areapv;
pv_oandm_npv = pv_oandm * factor2;
const_pv2 = pv_oandm_npv / Areapv;
% Wind
windg_oandm = oandm_wt * Areawt;
windg_oandm_npv = windg_oandm * factor2;
const_wt2 = windg_oandm_npv / Areawt;
% Battery
batt_oandm = oandm_batt * Capbatt;
batt_oandm_npv = batt_oandm * factor2;
const_batt2 = batt_oandm_npv / Capbatt;
%————————————————————————-%
% Salvage revenues
% Solar
pv_sal = sal_pv * Areapv;
pv_sal_npv = pv_sal * factor3a;
const_pv3 = pv_sal_npv / Areapv;
% Wind
windg_sal = sal_wt * Areawt;
windg_sal_npv = windg_sal * factor3b;
const_wt3 = windg_sal_npv / Areawt;
% Battery
batt_sal = sal_batt * Capbatt;
batt_sal_npv = batt_sal * factor3c;
const_batt3 = batt_sal_npv / Capbatt;
%————————————————————————-%
% Total system cost
% In general: system cost = capital cost + o&m cost – salvage revenue
system_cost = ((const_pv1 + const_pv2 – const_pv3) * Areapv) + …
((const_wt1 + const_wt2 – const_wt3) * Areawt) +((const_batt1 + const_batt2 – const_batt3) * Capbatt);
end
the ga script
nvars = 3; % number of input variables
fun = @cost; % objective function to be optimized (system cost)
lb = [16.3 6.865 16.8]; % lower bounds of input variables
ub = [32.6 22.882 33.6]; % lower bounds of input variables
nonlcon = @LPSP; % nonlinear constraint function (loss of power supply
% probability
% Optimization command
[X,fval] = ga(fun,nvars,[],[],[],[],lb,ub,nonlcon);
i can provide the exel data files you need to run the function
these are the errors i could not fix :
Error using .*
Matrix dimensions must agree.
Error in solar (line 12)
solargen = w .* x;
Error in LPSP (line 9)
s = solar(Areapv); % call solar function
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in constrValidate (line 23)
[cineq,ceq] = nonlcon(Iterate.x’);
Error in gacommon (line 132)
[LinearConstr, Iterate,nineqcstr,neqcstr,ncstr] = constrValidate(NonconFcn, …
Error in ga (line 336)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, …
Error in gen (line 28)
[X,fval] = ga(fun,nvars,[],[],[],[],lb,ub,nonlcon);
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation.i’m working on optimising a design of a hybrid PV/Wind energy system (with battery) using Genetic Algorithms ,and based on a research paper i have been able to code the following :
% Solar PV Generator script
function solargen = solar(Areapv)
% Input:
% Areapv = total area of all PV modules, one of the variables to be optimized
% x = solar irradiance (data read from an Excel file)
x = xlsread(‘éclairement_tlemcen.xlsx’,’A1:A8784′);
effpv = 0.227; % efficiency of the PV module specified by manufacturer
% Output:
% solargen = power produced by the PV generator (kW)
% solargen = Areapv * effpv * Irrad * 0.001;
w = effpv * Areapv * 0.001;
solargen = w .* x;
end
wind turbine script
% Wind Generator script
function windgen = windpower(Areawt)
% Inputs:
% Areawt = total rotor swept area of all wind turbines used (m2)
% Areawt is one of the variables to be optimized
coeff_wt = 45/100; % coefficient of power of wind turbine
rho = 1.1839; % density of air (kg/m3) at 1 atm pres and 25 degC temp
vci = 2.01168; % wind turbine cut-in/min wind speed (m/s)
vrat = 13.8582; % wind turbine rated wind speed (m/s)
vco = 17.8816; % wind turbine cut-out/max wind speed (m/s)
% vact = actual wind speed (data read from an Excel file)
vact = xlsread(‘wind_speed_tlemcen.xlsx’,’A1:A8784′);
y = length(vact); % number of wind speed data points
% windgen = power produced by the wind generator (kW)
b = zeros(1, y); % preallocation of memory outside loop
windgen = b.’;
for a = 1:y
if ((vact(a) < vci)||(vact(a) > vco)) % wind speed less than cut-in or greater than cut-out
z = 0;
elseif ((vact(a) >= vci)&&(vact(a) < vrat)) % wind speed between cut-in and rated
z = 0.5 * coeff_wt * rho * Areawt * (vrat.^3) * ((vact(a).^3 – vci.^3)/(vrat.^3 – vci.^3)) * 0.001;
else % wind speed between rated and cut-out
z = 0.5 * coeff_wt * rho * Areawt * (vrat.^3) * 0.001;
end
windgen(a) = z;
end
end
battery script
% Battery System script
function [battpower,Pload] = battery(Areapv,Areawt,Capbatt)
% Inputs:
% Areapv = total area of all PV modules used (m2)
% Areawt = total rotor swept area of all wind turbines used (m2)
% Capbatt = total energy capacity of all batteries used (kWh)
% The three inputs are the variables to be optimized
% Pload = load demand (data read from an Excel file)
Pl = xlsread(‘charge_tlemcen.xlsx’,’A1:A8784′);
Pload = 0.001 * Pl; % load power in kW
eff_inv = 88/100; % efficiency of inverter
eff_batt_cha = 92/100; % efficiency of battery charging
eff_batt_disch = 100/100; % efficiency of battery discharging
Ppv = solar(Areapv); % generation from solar
Pwind = windpower(Areawt); % generation from wind
soc_max = 98/100; % maximum state of charge of battery
dod_max = 80/100; % maximum depth of discharge
y = length(Pload);
% preallocation of memory outside loop for some variables
c = zeros(1, y);
Pgen = c.’;
d = zeros(1, y);
soc = d.’;
e = zeros(1, y);
dod = e.’;
f = zeros(1, y);
Pdump = f.’;
g = zeros(1, y);
battpower = g.’;
h = zeros(1, y);
Pdef = h.’;
soc(1) = soc_max; % initial state of charge of battery
dod(1) = 1 – soc(1); % initial state of discharge of battery
for b = 1:y
Pgen(b) = Ppv(b) + Pwind(b);
soc(b) = soc(b) + (battpower(b)/(1000*Capbatt));
if Pgen(b) > (Pload(b)/eff_inv) % generation > load
if soc(b) < soc_max % battery not charged fully
battpower(b) = (Pgen(b) – (Pload(b)/eff_inv)) *eff_batt_cha; % battery charges, battpower is +ve
else
soc(b) >= soc_max; % battery charged to maximum
battpower(b) = 0; % no more charging
Pdump(b) = Pgen(b) – (Pload(b)/eff_inv);
% surplus power is dumped after battery charges to maximum
end
elseif Pgen(b) < (Pload(b)/eff_inv) % generation < load
if (dod(b)) < dod_max % battery not dicharged to maximum
battpower(b) = -((Pload(b)/eff_inv) – Pgen(b)) * eff_batt_disch; % battery discharges, battpower is -ve
else
dod(b) >= dod_max; % battery discharged to maximum
battpower(b) = 0; % no more discharging
Pdef(b) = Pload(b) – (Pgen(b) + ((1000 * Capbatt)* ((soc(b)-(1-dod_max))))* eff_inv);
% deficit power persists after battery discharged fully
end
else % Pgen(b) = (Pload(b)/eff_inv) i.e. generation = load
battpower(b) = 0; % No charging or discharging
end
end
end
LPSP script which is the non linear constraint script
function [LPSP_value,LPSP_eq] = LPSP(Areapv,Areawt,Capbatt)
eff_inv = 88/100; % efficiency of inverter
s = solar(Areapv); % call solar function
w = windpower(Areawt); % call wind function
Pg = s + w; % generation = solar + wind
[b,Pl] = battery(Areapv,Areawt,Capbatt); % call battery function
Pgen = sum(Pg); % total generation
Pload = sum(Pl); % total load
battp = sum(b); % total battery power
LPS = sum(Pdef);
LPSP_value = (LPS / Pload) – 0.05; % LPSP <= 0.05
LPSP_eq = [];
end
the cost script which is the objective function
% Total System Cost script
% The total system cost is the sum of the following costs:
% Capital/investment costs
% Operation and maintenance costs
% Replacement costs
% Salvage revenue (negative cost)
% The present value of the above cost components are found for each of the
% three main system components: solar pv generator, wind generator and
% battery system; all costs are then added to get the total system cost
% The total system cost is the objective function to be optimized by a
% genetic algorithm. The constraints of this function are the loss of power
% supply probability (defined in a separate function) and the input
% variables.
function system_cost = cost(Areapv,Areawt,Capbatt)
%————————————————————————-%
% Constraints
Areapv_max = 20 * 1.63; % 20 PV modules maximum (32.6 m2 max area)
Areapv(Areapv>Areapv_max) = Areapv_max;
Areapv_min = 10 * 1.63; % 10 PV modules minimum (16.3 m2 min area)
Areapv(Areapv<Areapv_min) = Areapv_min;
Areawt_max = 10 * pi * (0.85344.^2); % 10 wind turbines maximum
% (22.8821 m2 max area)
Areawt(Areawt>Areawt_max) = Areawt_max;
Areawt_min = 3 * pi * (0.85344.^2); % 3 wind turbines minimum
% (6.8646 m2 min area)
Areawt(Areawt<Areawt_min) = Areawt_min;
Capbatt_max = 20 * 1.68; % 20 battery units maximum (33.6 kWh max)
Capbatt(Capbatt>Capbatt_max) = Capbatt_max;
Capbatt_min = 10 * 1.68; % 10 battery units minimum (16.8 kWh min)
Capbatt(Capbatt<Capbatt_min) = Capbatt_min;
%————————————————————————-%
% Project lifetime
%proj_life = 25; % years
%————————————————————————-%
% Rates applicable
%int = 5/100; % interest rate that affects all costs
%infl = 3/100; % inflation rate that affects salvage costs
%inc = 4/100; % non-inflation rate at which non-salvage costs increase
%————————————————————————-%
% Solar specifications
cap_pv = 300/1.63; % capital cost of PV module (184.0491 UK pounds/m2)
oandm_pv = 7.5/1.63; % o & m cost of PV module (4.6012 UK pounds/m2/yr)
sal_pv = 60/1.63; % salvage revenue of PV module (36.8098 UK pounds/m2)
%life_pv = 25; % lifetime of PV module (years)
%rep_pv = (proj_life / life_pv) – 1; % number of replacements in project (0)
%————————————————————————-%
% Wind specifications
cap_wt = 1125/(pi*(0.85344.^2)); % capital cost of turbine
% (491.6507 UK pounds/m2)
oandm_wt = 168.75/(pi*(0.85344.^2)); % o & m cost of turbine
% (73.7476 UK pounds/m2/yr)
sal_wt = 225/(pi*(0.85344.^2)); % salvage revenue of turbine
% (98.3301 UK pounds/m2)
%life_wt = 12.5; % lifetime of turbine (years)
%rep_wt = (proj_life / life_wt) – 1; % number of replacements in project (1)
%————————————————————————-%
% Battery specifications
cap_batt = 364/1.68; % capital cost of battery (216.6667 UK pounds/kWh)
oandm_batt = 3.64/1.68; % o & m cost of battery (2.1667 UK pounds/kWh/yr)
sal_batt = 36.4/1.68; % salvage revenue of battery (21.6667 UK pounds/kWh)
%life_batt = 2.5; % lifetime of battery (years)
%rep_batt = (proj_life / life_batt) – 1; % number of replacements in project;
% (9)
%————————————————————————-%
% Useful factors for net present value
%fac1 = (1+inc)/(1+int); % 0.9905
%fac2 = (1+infl)/(1+int); % 0.9810
%factor1a = symsum(fac1.^((k-1)*life_wt),k,1,rep_wt);
factor1a = 1; % summation of fac1^(k-1)*life_wt) for turbine replacements
%factor1b = symsum(fac1.^((k-1)*life_batt),k,1,rep_batt);
factor1b = 8.1943; % summation of fac1.^((k-1)*life_batt) for battery
% replacements
%factor2 = symsum(fac1.^k,k,1,proj_life);
factor2 = 22.1282; % summation of fac1^k for project life
% factor2 = fac1 + (fac1.^2) + (fac1.^3) + … + (fac1.^25)
%factor3a = ((1+infl).^proj_life)/((1+int).^proj_life);
factor3a = 0.6183;
%factor3b = symsum(fac2.^(x*life_wt),x,1,rep_wt);
factor3b = 0.7863; % summation of fac2^(x*life_wt) for turbine life
%factor3c = symsum(fac2.^(x*life_batt),x,1,rep_batt);
factor3c = 7.1315; % summation of fac2^(x*life_batt) for battery life
%————————————————————————-%
% Capital costs and replacement costs
% Solar
pv_caprep = cap_pv * Areapv;
pv_caprep_npv = pv_caprep;
const_pv1 = pv_caprep_npv / Areapv;
% Wind
windg_caprep = cap_wt * Areawt;
windg_caprep_npv = windg_caprep * factor1a;
const_wt1 = windg_caprep_npv / Areawt;
% Battery
batt_caprep = cap_batt * Capbatt;
batt_caprep_npv = batt_caprep * factor1b;
const_batt1 = batt_caprep_npv / Capbatt;
%————————————————————————-%
% Operation and maintenance costs
% Solar
pv_oandm = oandm_pv * Areapv;
pv_oandm_npv = pv_oandm * factor2;
const_pv2 = pv_oandm_npv / Areapv;
% Wind
windg_oandm = oandm_wt * Areawt;
windg_oandm_npv = windg_oandm * factor2;
const_wt2 = windg_oandm_npv / Areawt;
% Battery
batt_oandm = oandm_batt * Capbatt;
batt_oandm_npv = batt_oandm * factor2;
const_batt2 = batt_oandm_npv / Capbatt;
%————————————————————————-%
% Salvage revenues
% Solar
pv_sal = sal_pv * Areapv;
pv_sal_npv = pv_sal * factor3a;
const_pv3 = pv_sal_npv / Areapv;
% Wind
windg_sal = sal_wt * Areawt;
windg_sal_npv = windg_sal * factor3b;
const_wt3 = windg_sal_npv / Areawt;
% Battery
batt_sal = sal_batt * Capbatt;
batt_sal_npv = batt_sal * factor3c;
const_batt3 = batt_sal_npv / Capbatt;
%————————————————————————-%
% Total system cost
% In general: system cost = capital cost + o&m cost – salvage revenue
system_cost = ((const_pv1 + const_pv2 – const_pv3) * Areapv) + …
((const_wt1 + const_wt2 – const_wt3) * Areawt) +((const_batt1 + const_batt2 – const_batt3) * Capbatt);
end
the ga script
nvars = 3; % number of input variables
fun = @cost; % objective function to be optimized (system cost)
lb = [16.3 6.865 16.8]; % lower bounds of input variables
ub = [32.6 22.882 33.6]; % lower bounds of input variables
nonlcon = @LPSP; % nonlinear constraint function (loss of power supply
% probability
% Optimization command
[X,fval] = ga(fun,nvars,[],[],[],[],lb,ub,nonlcon);
i can provide the exel data files you need to run the function
these are the errors i could not fix :
Error using .*
Matrix dimensions must agree.
Error in solar (line 12)
solargen = w .* x;
Error in LPSP (line 9)
s = solar(Areapv); % call solar function
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in constrValidate (line 23)
[cineq,ceq] = nonlcon(Iterate.x’);
Error in gacommon (line 132)
[LinearConstr, Iterate,nineqcstr,neqcstr,ncstr] = constrValidate(NonconFcn, …
Error in ga (line 336)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, …
Error in gen (line 28)
[X,fval] = ga(fun,nvars,[],[],[],[],lb,ub,nonlcon);
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation. i’m working on optimising a design of a hybrid PV/Wind energy system (with battery) using Genetic Algorithms ,and based on a research paper i have been able to code the following :
% Solar PV Generator script
function solargen = solar(Areapv)
% Input:
% Areapv = total area of all PV modules, one of the variables to be optimized
% x = solar irradiance (data read from an Excel file)
x = xlsread(‘éclairement_tlemcen.xlsx’,’A1:A8784′);
effpv = 0.227; % efficiency of the PV module specified by manufacturer
% Output:
% solargen = power produced by the PV generator (kW)
% solargen = Areapv * effpv * Irrad * 0.001;
w = effpv * Areapv * 0.001;
solargen = w .* x;
end
wind turbine script
% Wind Generator script
function windgen = windpower(Areawt)
% Inputs:
% Areawt = total rotor swept area of all wind turbines used (m2)
% Areawt is one of the variables to be optimized
coeff_wt = 45/100; % coefficient of power of wind turbine
rho = 1.1839; % density of air (kg/m3) at 1 atm pres and 25 degC temp
vci = 2.01168; % wind turbine cut-in/min wind speed (m/s)
vrat = 13.8582; % wind turbine rated wind speed (m/s)
vco = 17.8816; % wind turbine cut-out/max wind speed (m/s)
% vact = actual wind speed (data read from an Excel file)
vact = xlsread(‘wind_speed_tlemcen.xlsx’,’A1:A8784′);
y = length(vact); % number of wind speed data points
% windgen = power produced by the wind generator (kW)
b = zeros(1, y); % preallocation of memory outside loop
windgen = b.’;
for a = 1:y
if ((vact(a) < vci)||(vact(a) > vco)) % wind speed less than cut-in or greater than cut-out
z = 0;
elseif ((vact(a) >= vci)&&(vact(a) < vrat)) % wind speed between cut-in and rated
z = 0.5 * coeff_wt * rho * Areawt * (vrat.^3) * ((vact(a).^3 – vci.^3)/(vrat.^3 – vci.^3)) * 0.001;
else % wind speed between rated and cut-out
z = 0.5 * coeff_wt * rho * Areawt * (vrat.^3) * 0.001;
end
windgen(a) = z;
end
end
battery script
% Battery System script
function [battpower,Pload] = battery(Areapv,Areawt,Capbatt)
% Inputs:
% Areapv = total area of all PV modules used (m2)
% Areawt = total rotor swept area of all wind turbines used (m2)
% Capbatt = total energy capacity of all batteries used (kWh)
% The three inputs are the variables to be optimized
% Pload = load demand (data read from an Excel file)
Pl = xlsread(‘charge_tlemcen.xlsx’,’A1:A8784′);
Pload = 0.001 * Pl; % load power in kW
eff_inv = 88/100; % efficiency of inverter
eff_batt_cha = 92/100; % efficiency of battery charging
eff_batt_disch = 100/100; % efficiency of battery discharging
Ppv = solar(Areapv); % generation from solar
Pwind = windpower(Areawt); % generation from wind
soc_max = 98/100; % maximum state of charge of battery
dod_max = 80/100; % maximum depth of discharge
y = length(Pload);
% preallocation of memory outside loop for some variables
c = zeros(1, y);
Pgen = c.’;
d = zeros(1, y);
soc = d.’;
e = zeros(1, y);
dod = e.’;
f = zeros(1, y);
Pdump = f.’;
g = zeros(1, y);
battpower = g.’;
h = zeros(1, y);
Pdef = h.’;
soc(1) = soc_max; % initial state of charge of battery
dod(1) = 1 – soc(1); % initial state of discharge of battery
for b = 1:y
Pgen(b) = Ppv(b) + Pwind(b);
soc(b) = soc(b) + (battpower(b)/(1000*Capbatt));
if Pgen(b) > (Pload(b)/eff_inv) % generation > load
if soc(b) < soc_max % battery not charged fully
battpower(b) = (Pgen(b) – (Pload(b)/eff_inv)) *eff_batt_cha; % battery charges, battpower is +ve
else
soc(b) >= soc_max; % battery charged to maximum
battpower(b) = 0; % no more charging
Pdump(b) = Pgen(b) – (Pload(b)/eff_inv);
% surplus power is dumped after battery charges to maximum
end
elseif Pgen(b) < (Pload(b)/eff_inv) % generation < load
if (dod(b)) < dod_max % battery not dicharged to maximum
battpower(b) = -((Pload(b)/eff_inv) – Pgen(b)) * eff_batt_disch; % battery discharges, battpower is -ve
else
dod(b) >= dod_max; % battery discharged to maximum
battpower(b) = 0; % no more discharging
Pdef(b) = Pload(b) – (Pgen(b) + ((1000 * Capbatt)* ((soc(b)-(1-dod_max))))* eff_inv);
% deficit power persists after battery discharged fully
end
else % Pgen(b) = (Pload(b)/eff_inv) i.e. generation = load
battpower(b) = 0; % No charging or discharging
end
end
end
LPSP script which is the non linear constraint script
function [LPSP_value,LPSP_eq] = LPSP(Areapv,Areawt,Capbatt)
eff_inv = 88/100; % efficiency of inverter
s = solar(Areapv); % call solar function
w = windpower(Areawt); % call wind function
Pg = s + w; % generation = solar + wind
[b,Pl] = battery(Areapv,Areawt,Capbatt); % call battery function
Pgen = sum(Pg); % total generation
Pload = sum(Pl); % total load
battp = sum(b); % total battery power
LPS = sum(Pdef);
LPSP_value = (LPS / Pload) – 0.05; % LPSP <= 0.05
LPSP_eq = [];
end
the cost script which is the objective function
% Total System Cost script
% The total system cost is the sum of the following costs:
% Capital/investment costs
% Operation and maintenance costs
% Replacement costs
% Salvage revenue (negative cost)
% The present value of the above cost components are found for each of the
% three main system components: solar pv generator, wind generator and
% battery system; all costs are then added to get the total system cost
% The total system cost is the objective function to be optimized by a
% genetic algorithm. The constraints of this function are the loss of power
% supply probability (defined in a separate function) and the input
% variables.
function system_cost = cost(Areapv,Areawt,Capbatt)
%————————————————————————-%
% Constraints
Areapv_max = 20 * 1.63; % 20 PV modules maximum (32.6 m2 max area)
Areapv(Areapv>Areapv_max) = Areapv_max;
Areapv_min = 10 * 1.63; % 10 PV modules minimum (16.3 m2 min area)
Areapv(Areapv<Areapv_min) = Areapv_min;
Areawt_max = 10 * pi * (0.85344.^2); % 10 wind turbines maximum
% (22.8821 m2 max area)
Areawt(Areawt>Areawt_max) = Areawt_max;
Areawt_min = 3 * pi * (0.85344.^2); % 3 wind turbines minimum
% (6.8646 m2 min area)
Areawt(Areawt<Areawt_min) = Areawt_min;
Capbatt_max = 20 * 1.68; % 20 battery units maximum (33.6 kWh max)
Capbatt(Capbatt>Capbatt_max) = Capbatt_max;
Capbatt_min = 10 * 1.68; % 10 battery units minimum (16.8 kWh min)
Capbatt(Capbatt<Capbatt_min) = Capbatt_min;
%————————————————————————-%
% Project lifetime
%proj_life = 25; % years
%————————————————————————-%
% Rates applicable
%int = 5/100; % interest rate that affects all costs
%infl = 3/100; % inflation rate that affects salvage costs
%inc = 4/100; % non-inflation rate at which non-salvage costs increase
%————————————————————————-%
% Solar specifications
cap_pv = 300/1.63; % capital cost of PV module (184.0491 UK pounds/m2)
oandm_pv = 7.5/1.63; % o & m cost of PV module (4.6012 UK pounds/m2/yr)
sal_pv = 60/1.63; % salvage revenue of PV module (36.8098 UK pounds/m2)
%life_pv = 25; % lifetime of PV module (years)
%rep_pv = (proj_life / life_pv) – 1; % number of replacements in project (0)
%————————————————————————-%
% Wind specifications
cap_wt = 1125/(pi*(0.85344.^2)); % capital cost of turbine
% (491.6507 UK pounds/m2)
oandm_wt = 168.75/(pi*(0.85344.^2)); % o & m cost of turbine
% (73.7476 UK pounds/m2/yr)
sal_wt = 225/(pi*(0.85344.^2)); % salvage revenue of turbine
% (98.3301 UK pounds/m2)
%life_wt = 12.5; % lifetime of turbine (years)
%rep_wt = (proj_life / life_wt) – 1; % number of replacements in project (1)
%————————————————————————-%
% Battery specifications
cap_batt = 364/1.68; % capital cost of battery (216.6667 UK pounds/kWh)
oandm_batt = 3.64/1.68; % o & m cost of battery (2.1667 UK pounds/kWh/yr)
sal_batt = 36.4/1.68; % salvage revenue of battery (21.6667 UK pounds/kWh)
%life_batt = 2.5; % lifetime of battery (years)
%rep_batt = (proj_life / life_batt) – 1; % number of replacements in project;
% (9)
%————————————————————————-%
% Useful factors for net present value
%fac1 = (1+inc)/(1+int); % 0.9905
%fac2 = (1+infl)/(1+int); % 0.9810
%factor1a = symsum(fac1.^((k-1)*life_wt),k,1,rep_wt);
factor1a = 1; % summation of fac1^(k-1)*life_wt) for turbine replacements
%factor1b = symsum(fac1.^((k-1)*life_batt),k,1,rep_batt);
factor1b = 8.1943; % summation of fac1.^((k-1)*life_batt) for battery
% replacements
%factor2 = symsum(fac1.^k,k,1,proj_life);
factor2 = 22.1282; % summation of fac1^k for project life
% factor2 = fac1 + (fac1.^2) + (fac1.^3) + … + (fac1.^25)
%factor3a = ((1+infl).^proj_life)/((1+int).^proj_life);
factor3a = 0.6183;
%factor3b = symsum(fac2.^(x*life_wt),x,1,rep_wt);
factor3b = 0.7863; % summation of fac2^(x*life_wt) for turbine life
%factor3c = symsum(fac2.^(x*life_batt),x,1,rep_batt);
factor3c = 7.1315; % summation of fac2^(x*life_batt) for battery life
%————————————————————————-%
% Capital costs and replacement costs
% Solar
pv_caprep = cap_pv * Areapv;
pv_caprep_npv = pv_caprep;
const_pv1 = pv_caprep_npv / Areapv;
% Wind
windg_caprep = cap_wt * Areawt;
windg_caprep_npv = windg_caprep * factor1a;
const_wt1 = windg_caprep_npv / Areawt;
% Battery
batt_caprep = cap_batt * Capbatt;
batt_caprep_npv = batt_caprep * factor1b;
const_batt1 = batt_caprep_npv / Capbatt;
%————————————————————————-%
% Operation and maintenance costs
% Solar
pv_oandm = oandm_pv * Areapv;
pv_oandm_npv = pv_oandm * factor2;
const_pv2 = pv_oandm_npv / Areapv;
% Wind
windg_oandm = oandm_wt * Areawt;
windg_oandm_npv = windg_oandm * factor2;
const_wt2 = windg_oandm_npv / Areawt;
% Battery
batt_oandm = oandm_batt * Capbatt;
batt_oandm_npv = batt_oandm * factor2;
const_batt2 = batt_oandm_npv / Capbatt;
%————————————————————————-%
% Salvage revenues
% Solar
pv_sal = sal_pv * Areapv;
pv_sal_npv = pv_sal * factor3a;
const_pv3 = pv_sal_npv / Areapv;
% Wind
windg_sal = sal_wt * Areawt;
windg_sal_npv = windg_sal * factor3b;
const_wt3 = windg_sal_npv / Areawt;
% Battery
batt_sal = sal_batt * Capbatt;
batt_sal_npv = batt_sal * factor3c;
const_batt3 = batt_sal_npv / Capbatt;
%————————————————————————-%
% Total system cost
% In general: system cost = capital cost + o&m cost – salvage revenue
system_cost = ((const_pv1 + const_pv2 – const_pv3) * Areapv) + …
((const_wt1 + const_wt2 – const_wt3) * Areawt) +((const_batt1 + const_batt2 – const_batt3) * Capbatt);
end
the ga script
nvars = 3; % number of input variables
fun = @cost; % objective function to be optimized (system cost)
lb = [16.3 6.865 16.8]; % lower bounds of input variables
ub = [32.6 22.882 33.6]; % lower bounds of input variables
nonlcon = @LPSP; % nonlinear constraint function (loss of power supply
% probability
% Optimization command
[X,fval] = ga(fun,nvars,[],[],[],[],lb,ub,nonlcon);
i can provide the exel data files you need to run the function
these are the errors i could not fix :
Error using .*
Matrix dimensions must agree.
Error in solar (line 12)
solargen = w .* x;
Error in LPSP (line 9)
s = solar(Areapv); % call solar function
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in constrValidate (line 23)
[cineq,ceq] = nonlcon(Iterate.x’);
Error in gacommon (line 132)
[LinearConstr, Iterate,nineqcstr,neqcstr,ncstr] = constrValidate(NonconFcn, …
Error in ga (line 336)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, …
Error in gen (line 28)
[X,fval] = ga(fun,nvars,[],[],[],[],lb,ub,nonlcon);
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation. genetic algorithm MATLAB Answers — New Questions
Error with the simulink downsample component
Hello,
I am using the downsample component in simulink, but I am getting the error message:
"Nonzero sample time offsets are not supported"
during C++ generation.
My sample offset is set to 0 in the block parameters window. I also tried to use a workspace variable set to 0 to see if it makes a difference. No change.
I have used this block before without any problem. Any recommendation on how to debug this?
Thanks!Hello,
I am using the downsample component in simulink, but I am getting the error message:
"Nonzero sample time offsets are not supported"
during C++ generation.
My sample offset is set to 0 in the block parameters window. I also tried to use a workspace variable set to 0 to see if it makes a difference. No change.
I have used this block before without any problem. Any recommendation on how to debug this?
Thanks! Hello,
I am using the downsample component in simulink, but I am getting the error message:
"Nonzero sample time offsets are not supported"
during C++ generation.
My sample offset is set to 0 in the block parameters window. I also tried to use a workspace variable set to 0 to see if it makes a difference. No change.
I have used this block before without any problem. Any recommendation on how to debug this?
Thanks! simulink, downsample MATLAB Answers — New Questions
can simulink code generated unique codes can be kept same irrespective of simulink version ?
whenever matlab generates a code it assigns unique code for each subsystem and its used for classification of parameters from that particular subsytem , here the problem is everytime the user uses different version of matlab ,in the subsystem this code numbers gets changed and there is lot of manual work involved in mapping these parameters used in hand written codes for interfaces , hence I wanted to check if there is any configuration settings available in the simulink to keep the unique subsystem code representations same irrespective of code gen in any version of matlab/simulink ??whenever matlab generates a code it assigns unique code for each subsystem and its used for classification of parameters from that particular subsytem , here the problem is everytime the user uses different version of matlab ,in the subsystem this code numbers gets changed and there is lot of manual work involved in mapping these parameters used in hand written codes for interfaces , hence I wanted to check if there is any configuration settings available in the simulink to keep the unique subsystem code representations same irrespective of code gen in any version of matlab/simulink ?? whenever matlab generates a code it assigns unique code for each subsystem and its used for classification of parameters from that particular subsytem , here the problem is everytime the user uses different version of matlab ,in the subsystem this code numbers gets changed and there is lot of manual work involved in mapping these parameters used in hand written codes for interfaces , hence I wanted to check if there is any configuration settings available in the simulink to keep the unique subsystem code representations same irrespective of code gen in any version of matlab/simulink ?? simulink generated code MATLAB Answers — New Questions
Centralized vs Decentralized Training for Multi Agent Reinforcement Learning
What exactly are the differences in centralized and decentralized training for multi agent reinforcement learning? Is centralized learning the same as the paradigm of CTDE (centralized training and decentralized execution) that is seen in much of the multi agent RL literature? When I run centralized training , the main difference I notice is that it appears that all agents are receiving the same Q0 value, which I believe means they have the same critic. I see that both methods are used in the tutorials, so I’m trying to get a clearer picture of what the differences are and when to use one versus the other.What exactly are the differences in centralized and decentralized training for multi agent reinforcement learning? Is centralized learning the same as the paradigm of CTDE (centralized training and decentralized execution) that is seen in much of the multi agent RL literature? When I run centralized training , the main difference I notice is that it appears that all agents are receiving the same Q0 value, which I believe means they have the same critic. I see that both methods are used in the tutorials, so I’m trying to get a clearer picture of what the differences are and when to use one versus the other. What exactly are the differences in centralized and decentralized training for multi agent reinforcement learning? Is centralized learning the same as the paradigm of CTDE (centralized training and decentralized execution) that is seen in much of the multi agent RL literature? When I run centralized training , the main difference I notice is that it appears that all agents are receiving the same Q0 value, which I believe means they have the same critic. I see that both methods are used in the tutorials, so I’m trying to get a clearer picture of what the differences are and when to use one versus the other. reinforcement learning MATLAB Answers — New Questions
The simulation time set by reinforcement learning is inconsistent with the training time
The simulation time set by reinforcement learning is inconsistent with the training time。The simulation time set by reinforcement learning is inconsistent with the training time。 The simulation time set by reinforcement learning is inconsistent with the training time。 reinforcement learning MATLAB Answers — New Questions
References to multi-agent reinforcement learning schemes in the reinforcement learning toolbox
Can somebody provide several references on multi-agent reinforcement learning schemes in reinforcement learning toolbox?Can somebody provide several references on multi-agent reinforcement learning schemes in reinforcement learning toolbox? Can somebody provide several references on multi-agent reinforcement learning schemes in reinforcement learning toolbox? reinforcement learning, muti-agent MATLAB Answers — New Questions
Training CNN with custom miniBatchDatastore thows cryptic error
I am trying to train a CNN model for a classification task. The input to the model is a `1x1024x2` frame and I have the following network:
layers =
28×1 Layer array with layers:
1 ‘Input Layer’ Image Input 1×1024×2 images
2 ‘CNN1’ 2-D Convolution 16 1×8 convolutions with stride [1 1] and padding ‘same’
3 ‘BN1’ Batch Normalization Batch normalization
4 ‘ReLU1’ ReLU ReLU
5 ‘MaxPool1’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
6 ‘CNN2’ 2-D Convolution 24 1×8 convolutions with stride [1 1] and padding ‘same’
7 ‘BN2’ Batch Normalization Batch normalization
8 ‘ReLU2’ ReLU ReLU
9 ‘MaxPool2’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
10 ‘CNN3’ 2-D Convolution 32 1×8 convolutions with stride [1 1] and padding ‘same’
11 ‘BN3’ Batch Normalization Batch normalization
12 ‘ReLU3’ ReLU ReLU
13 ‘MaxPool3’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
14 ‘CNN4’ 2-D Convolution 48 1×8 convolutions with stride [1 1] and padding ‘same’
15 ‘BN4’ Batch Normalization Batch normalization
16 ‘ReLU4’ ReLU ReLU
17 ‘MaxPool4’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
18 ‘CNN5’ 2-D Convolution 64 1×8 convolutions with stride [1 1] and padding ‘same’
19 ‘BN5’ Batch Normalization Batch normalization
20 ‘ReLU5’ ReLU ReLU
21 ‘MaxPool5’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
22 ‘CNN6’ 2-D Convolution 96 1×8 convolutions with stride [1 1] and padding ‘same’
23 ‘BN6’ Batch Normalization Batch normalization
24 ‘ReLU6’ ReLU ReLU
25 ‘AP1’ 2-D Average Pooling 1×32 average pooling with stride [1 1] and padding [0 0 0 0]
26 ‘FC1’ Fully Connected 24 fully connected layer
27 ‘SoftMax’ Softmax softmax
28 ‘Output’ Classification Output crossentropyex
I’m using a custom minibatch dataset to train the model. The read funtion returns the following table structure:
i’m using these training options:
% Specify training options
options = trainingOptions(‘sgdm’, …
‘MiniBatchSize’, miniBatchSize, …
‘MaxEpochs’, 10, …
‘Verbose’, true, …
‘Plots’, ‘training-progress’);
% Train the network
net = trainNetwork(mbds, layers, options);
and i get the following error:
Error using trainNetwork
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values.
Caused by:
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values.
I’ve been stuck on this for a while now, and theres no way to inspect the trainNetwork code to properly debug. I’d appreciate your suggestions. Thank you.
Paul Osinowo
Graduate Student
University of StrathclydeI am trying to train a CNN model for a classification task. The input to the model is a `1x1024x2` frame and I have the following network:
layers =
28×1 Layer array with layers:
1 ‘Input Layer’ Image Input 1×1024×2 images
2 ‘CNN1’ 2-D Convolution 16 1×8 convolutions with stride [1 1] and padding ‘same’
3 ‘BN1’ Batch Normalization Batch normalization
4 ‘ReLU1’ ReLU ReLU
5 ‘MaxPool1’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
6 ‘CNN2’ 2-D Convolution 24 1×8 convolutions with stride [1 1] and padding ‘same’
7 ‘BN2’ Batch Normalization Batch normalization
8 ‘ReLU2’ ReLU ReLU
9 ‘MaxPool2’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
10 ‘CNN3’ 2-D Convolution 32 1×8 convolutions with stride [1 1] and padding ‘same’
11 ‘BN3’ Batch Normalization Batch normalization
12 ‘ReLU3’ ReLU ReLU
13 ‘MaxPool3’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
14 ‘CNN4’ 2-D Convolution 48 1×8 convolutions with stride [1 1] and padding ‘same’
15 ‘BN4’ Batch Normalization Batch normalization
16 ‘ReLU4’ ReLU ReLU
17 ‘MaxPool4’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
18 ‘CNN5’ 2-D Convolution 64 1×8 convolutions with stride [1 1] and padding ‘same’
19 ‘BN5’ Batch Normalization Batch normalization
20 ‘ReLU5’ ReLU ReLU
21 ‘MaxPool5’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
22 ‘CNN6’ 2-D Convolution 96 1×8 convolutions with stride [1 1] and padding ‘same’
23 ‘BN6’ Batch Normalization Batch normalization
24 ‘ReLU6’ ReLU ReLU
25 ‘AP1’ 2-D Average Pooling 1×32 average pooling with stride [1 1] and padding [0 0 0 0]
26 ‘FC1’ Fully Connected 24 fully connected layer
27 ‘SoftMax’ Softmax softmax
28 ‘Output’ Classification Output crossentropyex
I’m using a custom minibatch dataset to train the model. The read funtion returns the following table structure:
i’m using these training options:
% Specify training options
options = trainingOptions(‘sgdm’, …
‘MiniBatchSize’, miniBatchSize, …
‘MaxEpochs’, 10, …
‘Verbose’, true, …
‘Plots’, ‘training-progress’);
% Train the network
net = trainNetwork(mbds, layers, options);
and i get the following error:
Error using trainNetwork
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values.
Caused by:
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values.
I’ve been stuck on this for a while now, and theres no way to inspect the trainNetwork code to properly debug. I’d appreciate your suggestions. Thank you.
Paul Osinowo
Graduate Student
University of Strathclyde I am trying to train a CNN model for a classification task. The input to the model is a `1x1024x2` frame and I have the following network:
layers =
28×1 Layer array with layers:
1 ‘Input Layer’ Image Input 1×1024×2 images
2 ‘CNN1’ 2-D Convolution 16 1×8 convolutions with stride [1 1] and padding ‘same’
3 ‘BN1’ Batch Normalization Batch normalization
4 ‘ReLU1’ ReLU ReLU
5 ‘MaxPool1’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
6 ‘CNN2’ 2-D Convolution 24 1×8 convolutions with stride [1 1] and padding ‘same’
7 ‘BN2’ Batch Normalization Batch normalization
8 ‘ReLU2’ ReLU ReLU
9 ‘MaxPool2’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
10 ‘CNN3’ 2-D Convolution 32 1×8 convolutions with stride [1 1] and padding ‘same’
11 ‘BN3’ Batch Normalization Batch normalization
12 ‘ReLU3’ ReLU ReLU
13 ‘MaxPool3’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
14 ‘CNN4’ 2-D Convolution 48 1×8 convolutions with stride [1 1] and padding ‘same’
15 ‘BN4’ Batch Normalization Batch normalization
16 ‘ReLU4’ ReLU ReLU
17 ‘MaxPool4’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
18 ‘CNN5’ 2-D Convolution 64 1×8 convolutions with stride [1 1] and padding ‘same’
19 ‘BN5’ Batch Normalization Batch normalization
20 ‘ReLU5’ ReLU ReLU
21 ‘MaxPool5’ 2-D Max Pooling 1×2 max pooling with stride [1 2] and padding [0 0 0 0]
22 ‘CNN6’ 2-D Convolution 96 1×8 convolutions with stride [1 1] and padding ‘same’
23 ‘BN6’ Batch Normalization Batch normalization
24 ‘ReLU6’ ReLU ReLU
25 ‘AP1’ 2-D Average Pooling 1×32 average pooling with stride [1 1] and padding [0 0 0 0]
26 ‘FC1’ Fully Connected 24 fully connected layer
27 ‘SoftMax’ Softmax softmax
28 ‘Output’ Classification Output crossentropyex
I’m using a custom minibatch dataset to train the model. The read funtion returns the following table structure:
i’m using these training options:
% Specify training options
options = trainingOptions(‘sgdm’, …
‘MiniBatchSize’, miniBatchSize, …
‘MaxEpochs’, 10, …
‘Verbose’, true, …
‘Plots’, ‘training-progress’);
% Train the network
net = trainNetwork(mbds, layers, options);
and i get the following error:
Error using trainNetwork
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values.
Caused by:
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values.
I’ve been stuck on this for a while now, and theres no way to inspect the trainNetwork code to properly debug. I’d appreciate your suggestions. Thank you.
Paul Osinowo
Graduate Student
University of Strathclyde deep learning, cnn MATLAB Answers — New Questions
Adding a column to a UITable and then using it.
After a few hours of trying I finally was able to add a column to a UITable
A = zeros([1 size(app.StimInputTable.Data,1)]);
app.StimInputTable.Data.Var4 = A’; % Have to make A a column vector!
for ii = 1:size(app.StimInputTable.Data,1)
app.StimInputTable.Var4(ii) = …
app.StimInputTable.Data.Var3(ii)/app.StimInputTable.Data.Var2(ii);
But now…
assigning a value to Our new column Var4 gives me
Unrecognized method, property, or field ‘Var4’ for class ‘matlab.ui.control.Table’.
It know what app.StimInputTable.Data.Var3(ii)/app.StimInputTable.Data.Var2(ii);
is so now put it in Var4! How hard can that be?
K>> app.StimInputTable.Data
ans =
4×4 table
Var1 Var2 Var3 Var4
____ ____ ____ ____
4 5 0 0
5 4 1 0
2 3 2 0
3 2 5 0
I can do it 1 row at a time from theCommand window:
K>> app.StimInputTable.Data
ii = 1 (etc)
K>> app.StimInputTable.Data.Var4(ii) = app.StimInputTable.Data.Var3(ii)/app.StimInputTable.Data.Var2(ii)
Although the "answer" I get is my whole
app =
MouseOdor4 with properties:
MouseOdor: [1×1 Figure]
all the properties of the whole app I won’t bore you with
K>> app.StimInputTable.Data
ans =
4×4 table
Var1 Var2 Var3 Var4
____ ____ ____ _______
4 5 0 1
5 4 1 2
2 3 2 0.66667
3 2 5 2.5
Look it worked!
Next step if you don’t mind anwering is to sort the table by the Var4 columnAfter a few hours of trying I finally was able to add a column to a UITable
A = zeros([1 size(app.StimInputTable.Data,1)]);
app.StimInputTable.Data.Var4 = A’; % Have to make A a column vector!
for ii = 1:size(app.StimInputTable.Data,1)
app.StimInputTable.Var4(ii) = …
app.StimInputTable.Data.Var3(ii)/app.StimInputTable.Data.Var2(ii);
But now…
assigning a value to Our new column Var4 gives me
Unrecognized method, property, or field ‘Var4’ for class ‘matlab.ui.control.Table’.
It know what app.StimInputTable.Data.Var3(ii)/app.StimInputTable.Data.Var2(ii);
is so now put it in Var4! How hard can that be?
K>> app.StimInputTable.Data
ans =
4×4 table
Var1 Var2 Var3 Var4
____ ____ ____ ____
4 5 0 0
5 4 1 0
2 3 2 0
3 2 5 0
I can do it 1 row at a time from theCommand window:
K>> app.StimInputTable.Data
ii = 1 (etc)
K>> app.StimInputTable.Data.Var4(ii) = app.StimInputTable.Data.Var3(ii)/app.StimInputTable.Data.Var2(ii)
Although the "answer" I get is my whole
app =
MouseOdor4 with properties:
MouseOdor: [1×1 Figure]
all the properties of the whole app I won’t bore you with
K>> app.StimInputTable.Data
ans =
4×4 table
Var1 Var2 Var3 Var4
____ ____ ____ _______
4 5 0 1
5 4 1 2
2 3 2 0.66667
3 2 5 2.5
Look it worked!
Next step if you don’t mind anwering is to sort the table by the Var4 column After a few hours of trying I finally was able to add a column to a UITable
A = zeros([1 size(app.StimInputTable.Data,1)]);
app.StimInputTable.Data.Var4 = A’; % Have to make A a column vector!
for ii = 1:size(app.StimInputTable.Data,1)
app.StimInputTable.Var4(ii) = …
app.StimInputTable.Data.Var3(ii)/app.StimInputTable.Data.Var2(ii);
But now…
assigning a value to Our new column Var4 gives me
Unrecognized method, property, or field ‘Var4’ for class ‘matlab.ui.control.Table’.
It know what app.StimInputTable.Data.Var3(ii)/app.StimInputTable.Data.Var2(ii);
is so now put it in Var4! How hard can that be?
K>> app.StimInputTable.Data
ans =
4×4 table
Var1 Var2 Var3 Var4
____ ____ ____ ____
4 5 0 0
5 4 1 0
2 3 2 0
3 2 5 0
I can do it 1 row at a time from theCommand window:
K>> app.StimInputTable.Data
ii = 1 (etc)
K>> app.StimInputTable.Data.Var4(ii) = app.StimInputTable.Data.Var3(ii)/app.StimInputTable.Data.Var2(ii)
Although the "answer" I get is my whole
app =
MouseOdor4 with properties:
MouseOdor: [1×1 Figure]
all the properties of the whole app I won’t bore you with
K>> app.StimInputTable.Data
ans =
4×4 table
Var1 Var2 Var3 Var4
____ ____ ____ _______
4 5 0 1
5 4 1 2
2 3 2 0.66667
3 2 5 2.5
Look it worked!
Next step if you don’t mind anwering is to sort the table by the Var4 column add column to table MATLAB Answers — New Questions
Where to find the coordinates info of image labelar’s bounding boxes?
How can I check the coornates info of the image labeler below?How can I check the coornates info of the image labeler below? How can I check the coornates info of the image labeler below? matlab, machine learning, image labeler MATLAB Answers — New Questions
Is the error initializing Java Preferences Failed in matlabrc important?
I’m a student and tried downloading a pirated version of matlab, which obviously didn’t work. I then removed that program from my computer, and downloaded the trial version of matlab. However, when I load up matlab, the above error appears.
Wondering what will be affected by it, and how can I get rid of that error.I’m a student and tried downloading a pirated version of matlab, which obviously didn’t work. I then removed that program from my computer, and downloaded the trial version of matlab. However, when I load up matlab, the above error appears.
Wondering what will be affected by it, and how can I get rid of that error. I’m a student and tried downloading a pirated version of matlab, which obviously didn’t work. I then removed that program from my computer, and downloaded the trial version of matlab. However, when I load up matlab, the above error appears.
Wondering what will be affected by it, and how can I get rid of that error. error, java, preferences, startup, library MATLAB Answers — New Questions
How can I plot the following data? Do I have to convert it first to another form?
Hey All,
I’m trying to plot various graphs of the following data but I have no clue where to start. I’ve tried something like the following type of code.
x=zeros(1,10);
x(2:4) =1;
y= linspace(0,10,10);
plot(y,x)
But also tried:
plot(filledData(:,1,filledData(:,2))
I apologize if this is too much, complete beginner. Second day at it.
Thank you all,
JJHey All,
I’m trying to plot various graphs of the following data but I have no clue where to start. I’ve tried something like the following type of code.
x=zeros(1,10);
x(2:4) =1;
y= linspace(0,10,10);
plot(y,x)
But also tried:
plot(filledData(:,1,filledData(:,2))
I apologize if this is too much, complete beginner. Second day at it.
Thank you all,
JJ Hey All,
I’m trying to plot various graphs of the following data but I have no clue where to start. I’ve tried something like the following type of code.
x=zeros(1,10);
x(2:4) =1;
y= linspace(0,10,10);
plot(y,x)
But also tried:
plot(filledData(:,1,filledData(:,2))
I apologize if this is too much, complete beginner. Second day at it.
Thank you all,
JJ double, data, plot, plotting MATLAB Answers — New Questions
MATLAB app designer, how to update value of a property in declared callback function
Hello all,
I am rather new to MATLAB, and therefore a little unfamiliar with the app designer, apologies in advance.
I am trying to write a code that tracks the position of a stepper motor over serial communication. Currently, I have the setup such that it will callback the readSerialData Function everytime the terminator "CR" is reached.
Ideally I would like to access the value read. I wanted to save this value to the motorPos property of the app for use in separate functions later down the line. However, from tests, it seems that the value of app.motorPos does not update and remains the initial value of 0, as defined in the startup function. While it does display the correct value in the command window (from the disp(app.arduino) function), the value of the property app.arduino seem to remain 0, when called upon in later functions.
How should I go about updating the value of property motorPos?
Thanks,
Yuandi Wu
properties (Access = public)
arduino
motorPos
end
methods (Access = private)
function readSerialData(app,src)
app.motorPos = readline(src);
disp(app.motorPos);
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
delete(instrfindall);
app.arduino = serialport ("COM3", 9600, "Timeout", 0.1);
app.arduino.DataBits = 8;
configureTerminator(app.arduino,"CR")
configureCallback(app.arduino,"terminator",@readSerialData)
%initially, upon startup, display these values
app.motorPos = ‘0’;
disp(app.motorPos)
endHello all,
I am rather new to MATLAB, and therefore a little unfamiliar with the app designer, apologies in advance.
I am trying to write a code that tracks the position of a stepper motor over serial communication. Currently, I have the setup such that it will callback the readSerialData Function everytime the terminator "CR" is reached.
Ideally I would like to access the value read. I wanted to save this value to the motorPos property of the app for use in separate functions later down the line. However, from tests, it seems that the value of app.motorPos does not update and remains the initial value of 0, as defined in the startup function. While it does display the correct value in the command window (from the disp(app.arduino) function), the value of the property app.arduino seem to remain 0, when called upon in later functions.
How should I go about updating the value of property motorPos?
Thanks,
Yuandi Wu
properties (Access = public)
arduino
motorPos
end
methods (Access = private)
function readSerialData(app,src)
app.motorPos = readline(src);
disp(app.motorPos);
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
delete(instrfindall);
app.arduino = serialport ("COM3", 9600, "Timeout", 0.1);
app.arduino.DataBits = 8;
configureTerminator(app.arduino,"CR")
configureCallback(app.arduino,"terminator",@readSerialData)
%initially, upon startup, display these values
app.motorPos = ‘0’;
disp(app.motorPos)
end Hello all,
I am rather new to MATLAB, and therefore a little unfamiliar with the app designer, apologies in advance.
I am trying to write a code that tracks the position of a stepper motor over serial communication. Currently, I have the setup such that it will callback the readSerialData Function everytime the terminator "CR" is reached.
Ideally I would like to access the value read. I wanted to save this value to the motorPos property of the app for use in separate functions later down the line. However, from tests, it seems that the value of app.motorPos does not update and remains the initial value of 0, as defined in the startup function. While it does display the correct value in the command window (from the disp(app.arduino) function), the value of the property app.arduino seem to remain 0, when called upon in later functions.
How should I go about updating the value of property motorPos?
Thanks,
Yuandi Wu
properties (Access = public)
arduino
motorPos
end
methods (Access = private)
function readSerialData(app,src)
app.motorPos = readline(src);
disp(app.motorPos);
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
delete(instrfindall);
app.arduino = serialport ("COM3", 9600, "Timeout", 0.1);
app.arduino.DataBits = 8;
configureTerminator(app.arduino,"CR")
configureCallback(app.arduino,"terminator",@readSerialData)
%initially, upon startup, display these values
app.motorPos = ‘0’;
disp(app.motorPos)
end appdesigner, serial MATLAB Answers — New Questions