Category: Matlab
Category Archives: Matlab
High-Fidelity Motor design
Hey community members,
I’m writng to ask for your suggestions here. I want to model an electric bike in simscape with high-fidelity inverter and motor. I have already modelled an inverter which is working correctly, but when it comes to motor, im looking for 5-6Kw of motor.
In pre-parameterized motors, the power and required torque are not up to my requirements.
If I parameterized it myself, then all the data which needs to parameterize motor block sets are not given in the datasheets.
I want to calculate motor losses over a wide range of operating points.
What would you guys suggest, should I do in this situation?
Should I design my own motor in another software like ansys and co-simulate it with matlab.
I would be looking forward to your suggestions.
Thank You !Hey community members,
I’m writng to ask for your suggestions here. I want to model an electric bike in simscape with high-fidelity inverter and motor. I have already modelled an inverter which is working correctly, but when it comes to motor, im looking for 5-6Kw of motor.
In pre-parameterized motors, the power and required torque are not up to my requirements.
If I parameterized it myself, then all the data which needs to parameterize motor block sets are not given in the datasheets.
I want to calculate motor losses over a wide range of operating points.
What would you guys suggest, should I do in this situation?
Should I design my own motor in another software like ansys and co-simulate it with matlab.
I would be looking forward to your suggestions.
Thank You ! Hey community members,
I’m writng to ask for your suggestions here. I want to model an electric bike in simscape with high-fidelity inverter and motor. I have already modelled an inverter which is working correctly, but when it comes to motor, im looking for 5-6Kw of motor.
In pre-parameterized motors, the power and required torque are not up to my requirements.
If I parameterized it myself, then all the data which needs to parameterize motor block sets are not given in the datasheets.
I want to calculate motor losses over a wide range of operating points.
What would you guys suggest, should I do in this situation?
Should I design my own motor in another software like ansys and co-simulate it with matlab.
I would be looking forward to your suggestions.
Thank You ! power_electronics_control MATLAB Answers — New Questions
Planar Joint ‘car/Planar1’ has base and follower ports that are rigidly connected; it is ignored. Resolve this issue in order to simulate the model.
将solidworks 2022中的搭建好的三维模型导入到MATLAB r2022a中进行仿真时,出现了一个问题: Planar Joint ‘car/Planar1’ has base and follower ports that are rigidly connected; it is ignored. Resolve this issue in order to simulate the model.
导致模型仿真不能够正常进行。将solidworks 2022中的搭建好的三维模型导入到MATLAB r2022a中进行仿真时,出现了一个问题: Planar Joint ‘car/Planar1’ has base and follower ports that are rigidly connected; it is ignored. Resolve this issue in order to simulate the model.
导致模型仿真不能够正常进行。 将solidworks 2022中的搭建好的三维模型导入到MATLAB r2022a中进行仿真时,出现了一个问题: Planar Joint ‘car/Planar1’ has base and follower ports that are rigidly connected; it is ignored. Resolve this issue in order to simulate the model.
导致模型仿真不能够正常进行。 matlab, simulink MATLAB Answers — New Questions
How is the default line parameter calculated in Simulink?
In almost simulink parameter models, they use below default value
Resistance per unit length (Ohms/km) = [0.01273 0.3864]
Inductance per unit length (H/km) = [0.9337e-3 4.1264e-3]
Capacitance per unit length (F/km) = [12.74e-9 7.751e-9]
I want to know how it is calculated.
Thank you for your help in advance!In almost simulink parameter models, they use below default value
Resistance per unit length (Ohms/km) = [0.01273 0.3864]
Inductance per unit length (H/km) = [0.9337e-3 4.1264e-3]
Capacitance per unit length (F/km) = [12.74e-9 7.751e-9]
I want to know how it is calculated.
Thank you for your help in advance! In almost simulink parameter models, they use below default value
Resistance per unit length (Ohms/km) = [0.01273 0.3864]
Inductance per unit length (H/km) = [0.9337e-3 4.1264e-3]
Capacitance per unit length (F/km) = [12.74e-9 7.751e-9]
I want to know how it is calculated.
Thank you for your help in advance! parameter, simulink, lineparameter MATLAB Answers — New Questions
Embedded coder STM32 build successful but nothing happens on board
Hello, I have been using the matlab embedded coder support package for about a year for my project and till last week everything was running smoothly. I recieved an rtiostream error while compiling which i could bypass by making a new model again, however, in the process of resolving this issue, I made a clean reinstall of matlab and all the support packages. Now I am trying to compile the same programs again but nothing happens on the board. I am not getting any errors in Matlab and it says build and download successful but on the board everything is blank. the input and output pins are not even configured when you try to measure them with multimeter.
Has anyone faced this issue and know a workaround for the same?Hello, I have been using the matlab embedded coder support package for about a year for my project and till last week everything was running smoothly. I recieved an rtiostream error while compiling which i could bypass by making a new model again, however, in the process of resolving this issue, I made a clean reinstall of matlab and all the support packages. Now I am trying to compile the same programs again but nothing happens on the board. I am not getting any errors in Matlab and it says build and download successful but on the board everything is blank. the input and output pins are not even configured when you try to measure them with multimeter.
Has anyone faced this issue and know a workaround for the same? Hello, I have been using the matlab embedded coder support package for about a year for my project and till last week everything was running smoothly. I recieved an rtiostream error while compiling which i could bypass by making a new model again, however, in the process of resolving this issue, I made a clean reinstall of matlab and all the support packages. Now I am trying to compile the same programs again but nothing happens on the board. I am not getting any errors in Matlab and it says build and download successful but on the board everything is blank. the input and output pins are not even configured when you try to measure them with multimeter.
Has anyone faced this issue and know a workaround for the same? matlab, simulink, embedded coder, stm, stm32, embedded matlab function, matlab coder, code generation MATLAB Answers — New Questions
Execution of script as a function is not supported
Hello,
I donwloaded a function online. It works fine until the line 58 where I have "Execution of script mix_2d_lp_fonc as a function is not supported". I don’t know why, I am sure I am in the correct folder (I wrote which…).
I would be gratefull for your assistanceHello,
I donwloaded a function online. It works fine until the line 58 where I have "Execution of script mix_2d_lp_fonc as a function is not supported". I don’t know why, I am sure I am in the correct folder (I wrote which…).
I would be gratefull for your assistance Hello,
I donwloaded a function online. It works fine until the line 58 where I have "Execution of script mix_2d_lp_fonc as a function is not supported". I don’t know why, I am sure I am in the correct folder (I wrote which…).
I would be gratefull for your assistance matlab function, function, handles MATLAB Answers — New Questions
Read text file line by line to columns
Hello community,
I have the data in this form
.557 .331 .069 .065 .101 .052 .109 .045 .114 .041 .117 .041 .109 .451 .234 -.058 .347 .406 -.005 .948 .252 -.007 .140 .024 .124 .036 .113 .045 .105 .052 .097 .059 .090 .064 .085 .068 .080 .071 .077 .073 0.075
and I want the data to be read as this form
0.557
0.331
0.069
0.065
0.101
0.052
etc
Please helpHello community,
I have the data in this form
.557 .331 .069 .065 .101 .052 .109 .045 .114 .041 .117 .041 .109 .451 .234 -.058 .347 .406 -.005 .948 .252 -.007 .140 .024 .124 .036 .113 .045 .105 .052 .097 .059 .090 .064 .085 .068 .080 .071 .077 .073 0.075
and I want the data to be read as this form
0.557
0.331
0.069
0.065
0.101
0.052
etc
Please help Hello community,
I have the data in this form
.557 .331 .069 .065 .101 .052 .109 .045 .114 .041 .117 .041 .109 .451 .234 -.058 .347 .406 -.005 .948 .252 -.007 .140 .024 .124 .036 .113 .045 .105 .052 .097 .059 .090 .064 .085 .068 .080 .071 .077 .073 0.075
and I want the data to be read as this form
0.557
0.331
0.069
0.065
0.101
0.052
etc
Please help line to columns MATLAB Answers — New Questions
How to get depth information from surface image
I have written the following matlab code to do the following:-
* load rgb image of surface
* contrast stretch
* convert rgb to gray scale
* convert gray to binary image
* select appropriate portion of the image
* fill hole in the binary image
* find and plot the centroid of image
* estimate radius of circular part and plot circle
My aim is to develop the SIMPLEST matlab code for automatic detection of indentation and calculate the diameter and depth of the indentation (if possible other geometrical properties) from a sample image.
The code is shown below:
% read the image from file
rgbImage = imread(‘V1.nn.bmp’);
subplot(2,3,1);
imshow(rgbImage,[]);
axis on;
title(‘original image’);
% Image adjust
Istretch = imadjust(rgbImage,stretchlim(rgbImage));
subplot(2,3,2);
imshow(Istretch,[])
axis on;
title(‘Contrast stretched image’)
% convert the original image into gray image
gry = rgb2gray(Istretch);
subplot(2,3,3);
imshow(gry,[]);
axis on;
title(‘original gray image’);
% convert gray image to binary image
level = graythresh(Istretch);
binaryImage = im2bw(gry,level);
subplot(2,3,4);
imshow(binaryImage);
title(‘binary masked image’);
% select appropriate portion of the image
areafilt = bwareafilt(binaryImage, 1, ‘largest’);
subplot(2,3,5);
imshow(areafilt);
title(‘main part of the image’);
% fill hole in the binary image
fillHole=imfill(areafilt,’holes’);
subplot(2,3,6);
imshow(fillHole);
title(‘filled hole of the image’);
%% find and plot the centroid of image
stats = regionprops(‘table’,fillHole,’Centroid’,’Area’,…
‘MajorAxisLength’,’MinorAxisLength’,’EquivDiameter’)
figure;
imshow(fillHole);
centroids=cat(1,stats.Centroid);
areas=cat(1,stats.Area);
hold on;
plot(centroids(:,1), centroids(:,2), ‘r*’,’MarkerSize’, 10, ‘LineWidth’, 1);
hold off;
% estimate radius of circular part and plot circle
diameter = mean([stats.MajorAxisLength stats.MinorAxisLength],2)
radii = diameter/2
hold on
viscircles(centroids,radii);
hold off
title(‘circle with centroid of the image’);
%%
I = surf(gry);
I tried *surf* function for depth information and it seems to get messy. I need help from image specialist to improve the code from above to meet my aim. The image *V1.nn.bmp* is attached, please find it.
Thank you.I have written the following matlab code to do the following:-
* load rgb image of surface
* contrast stretch
* convert rgb to gray scale
* convert gray to binary image
* select appropriate portion of the image
* fill hole in the binary image
* find and plot the centroid of image
* estimate radius of circular part and plot circle
My aim is to develop the SIMPLEST matlab code for automatic detection of indentation and calculate the diameter and depth of the indentation (if possible other geometrical properties) from a sample image.
The code is shown below:
% read the image from file
rgbImage = imread(‘V1.nn.bmp’);
subplot(2,3,1);
imshow(rgbImage,[]);
axis on;
title(‘original image’);
% Image adjust
Istretch = imadjust(rgbImage,stretchlim(rgbImage));
subplot(2,3,2);
imshow(Istretch,[])
axis on;
title(‘Contrast stretched image’)
% convert the original image into gray image
gry = rgb2gray(Istretch);
subplot(2,3,3);
imshow(gry,[]);
axis on;
title(‘original gray image’);
% convert gray image to binary image
level = graythresh(Istretch);
binaryImage = im2bw(gry,level);
subplot(2,3,4);
imshow(binaryImage);
title(‘binary masked image’);
% select appropriate portion of the image
areafilt = bwareafilt(binaryImage, 1, ‘largest’);
subplot(2,3,5);
imshow(areafilt);
title(‘main part of the image’);
% fill hole in the binary image
fillHole=imfill(areafilt,’holes’);
subplot(2,3,6);
imshow(fillHole);
title(‘filled hole of the image’);
%% find and plot the centroid of image
stats = regionprops(‘table’,fillHole,’Centroid’,’Area’,…
‘MajorAxisLength’,’MinorAxisLength’,’EquivDiameter’)
figure;
imshow(fillHole);
centroids=cat(1,stats.Centroid);
areas=cat(1,stats.Area);
hold on;
plot(centroids(:,1), centroids(:,2), ‘r*’,’MarkerSize’, 10, ‘LineWidth’, 1);
hold off;
% estimate radius of circular part and plot circle
diameter = mean([stats.MajorAxisLength stats.MinorAxisLength],2)
radii = diameter/2
hold on
viscircles(centroids,radii);
hold off
title(‘circle with centroid of the image’);
%%
I = surf(gry);
I tried *surf* function for depth information and it seems to get messy. I need help from image specialist to improve the code from above to meet my aim. The image *V1.nn.bmp* is attached, please find it.
Thank you. I have written the following matlab code to do the following:-
* load rgb image of surface
* contrast stretch
* convert rgb to gray scale
* convert gray to binary image
* select appropriate portion of the image
* fill hole in the binary image
* find and plot the centroid of image
* estimate radius of circular part and plot circle
My aim is to develop the SIMPLEST matlab code for automatic detection of indentation and calculate the diameter and depth of the indentation (if possible other geometrical properties) from a sample image.
The code is shown below:
% read the image from file
rgbImage = imread(‘V1.nn.bmp’);
subplot(2,3,1);
imshow(rgbImage,[]);
axis on;
title(‘original image’);
% Image adjust
Istretch = imadjust(rgbImage,stretchlim(rgbImage));
subplot(2,3,2);
imshow(Istretch,[])
axis on;
title(‘Contrast stretched image’)
% convert the original image into gray image
gry = rgb2gray(Istretch);
subplot(2,3,3);
imshow(gry,[]);
axis on;
title(‘original gray image’);
% convert gray image to binary image
level = graythresh(Istretch);
binaryImage = im2bw(gry,level);
subplot(2,3,4);
imshow(binaryImage);
title(‘binary masked image’);
% select appropriate portion of the image
areafilt = bwareafilt(binaryImage, 1, ‘largest’);
subplot(2,3,5);
imshow(areafilt);
title(‘main part of the image’);
% fill hole in the binary image
fillHole=imfill(areafilt,’holes’);
subplot(2,3,6);
imshow(fillHole);
title(‘filled hole of the image’);
%% find and plot the centroid of image
stats = regionprops(‘table’,fillHole,’Centroid’,’Area’,…
‘MajorAxisLength’,’MinorAxisLength’,’EquivDiameter’)
figure;
imshow(fillHole);
centroids=cat(1,stats.Centroid);
areas=cat(1,stats.Area);
hold on;
plot(centroids(:,1), centroids(:,2), ‘r*’,’MarkerSize’, 10, ‘LineWidth’, 1);
hold off;
% estimate radius of circular part and plot circle
diameter = mean([stats.MajorAxisLength stats.MinorAxisLength],2)
radii = diameter/2
hold on
viscircles(centroids,radii);
hold off
title(‘circle with centroid of the image’);
%%
I = surf(gry);
I tried *surf* function for depth information and it seems to get messy. I need help from image specialist to improve the code from above to meet my aim. The image *V1.nn.bmp* is attached, please find it.
Thank you. image analysis, image processing, surface geometry MATLAB Answers — New Questions
BLE Communication does not work (it is blocked)
Hi everyone,
I am trying to connect an Arduino Nano BLE 33 to my PC through MATLAB. I am using Win11 on my PC, and I actually do not know how Arduino is programmed (but it is a minor problem for now).
I just need to make sure that I can connect the device to Matlab, and I went through BLE Matlab documentation.
Firstly, I have checked my device is present and running blelist function I got some available devices and mine too:
Index Name Address RSSI Advertisement
_____ __________________ ______________ ____ _____________
1 "LE_WH-CH700N" "38184CD24082" -55 1×1 struct
2 "SC-Device" "0456142755E8" -65 1×1 struct
3 "" "7FB73C7AA99D" -68 1×1 struct
I am interested in second position device: SC-Device.
To the point I need I went to run ble function as follows:
bt = ble("0456142755E8")
I expected to create a Bluetooth Object which can handle some basic functions to write and read data. When I run ble function (as cited above), Matlab keeps stopping for long time as long as I forced closing the window. Using ctrl+c to interrupt the process I did not get any feedbacks, and Matlab keeps Busy status.
Does anyone know why I get this behaviour?
Thanks for your support, it would be really appreciated.
Best,
VHi everyone,
I am trying to connect an Arduino Nano BLE 33 to my PC through MATLAB. I am using Win11 on my PC, and I actually do not know how Arduino is programmed (but it is a minor problem for now).
I just need to make sure that I can connect the device to Matlab, and I went through BLE Matlab documentation.
Firstly, I have checked my device is present and running blelist function I got some available devices and mine too:
Index Name Address RSSI Advertisement
_____ __________________ ______________ ____ _____________
1 "LE_WH-CH700N" "38184CD24082" -55 1×1 struct
2 "SC-Device" "0456142755E8" -65 1×1 struct
3 "" "7FB73C7AA99D" -68 1×1 struct
I am interested in second position device: SC-Device.
To the point I need I went to run ble function as follows:
bt = ble("0456142755E8")
I expected to create a Bluetooth Object which can handle some basic functions to write and read data. When I run ble function (as cited above), Matlab keeps stopping for long time as long as I forced closing the window. Using ctrl+c to interrupt the process I did not get any feedbacks, and Matlab keeps Busy status.
Does anyone know why I get this behaviour?
Thanks for your support, it would be really appreciated.
Best,
V Hi everyone,
I am trying to connect an Arduino Nano BLE 33 to my PC through MATLAB. I am using Win11 on my PC, and I actually do not know how Arduino is programmed (but it is a minor problem for now).
I just need to make sure that I can connect the device to Matlab, and I went through BLE Matlab documentation.
Firstly, I have checked my device is present and running blelist function I got some available devices and mine too:
Index Name Address RSSI Advertisement
_____ __________________ ______________ ____ _____________
1 "LE_WH-CH700N" "38184CD24082" -55 1×1 struct
2 "SC-Device" "0456142755E8" -65 1×1 struct
3 "" "7FB73C7AA99D" -68 1×1 struct
I am interested in second position device: SC-Device.
To the point I need I went to run ble function as follows:
bt = ble("0456142755E8")
I expected to create a Bluetooth Object which can handle some basic functions to write and read data. When I run ble function (as cited above), Matlab keeps stopping for long time as long as I forced closing the window. Using ctrl+c to interrupt the process I did not get any feedbacks, and Matlab keeps Busy status.
Does anyone know why I get this behaviour?
Thanks for your support, it would be really appreciated.
Best,
V bluetooth, ble, arduino, communication MATLAB Answers — New Questions
calculating on time of signal
i have 2 square signal with the same amplitude=5 but 2 different on time the first one stays on for 0.4 seconds and the other one for 0.6 and i need a block or a code to use in matlab function that can calculate the time and if it is =0.4 a bit 0 will be the output and if on time was 0.6 bit 1 will be the output.i have 2 square signal with the same amplitude=5 but 2 different on time the first one stays on for 0.4 seconds and the other one for 0.6 and i need a block or a code to use in matlab function that can calculate the time and if it is =0.4 a bit 0 will be the output and if on time was 0.6 bit 1 will be the output. i have 2 square signal with the same amplitude=5 but 2 different on time the first one stays on for 0.4 seconds and the other one for 0.6 and i need a block or a code to use in matlab function that can calculate the time and if it is =0.4 a bit 0 will be the output and if on time was 0.6 bit 1 will be the output. signal, simulink MATLAB Answers — New Questions
Any tool in Matlab to plot graphically a 2-d manipulator with elastic joint?
Hi everyone,
I have a set of coordinate points in 2-d dimension, and the angular velocity of the joints of a manipulator with elastic joint.
Exist any tool where "I can just" insert coordinates and angular velocity to see graphically what happen? Something more interesting from a graphic point of view instead of plotting simple lines.
Thanks to those who want to help me.Hi everyone,
I have a set of coordinate points in 2-d dimension, and the angular velocity of the joints of a manipulator with elastic joint.
Exist any tool where "I can just" insert coordinates and angular velocity to see graphically what happen? Something more interesting from a graphic point of view instead of plotting simple lines.
Thanks to those who want to help me. Hi everyone,
I have a set of coordinate points in 2-d dimension, and the angular velocity of the joints of a manipulator with elastic joint.
Exist any tool where "I can just" insert coordinates and angular velocity to see graphically what happen? Something more interesting from a graphic point of view instead of plotting simple lines.
Thanks to those who want to help me. 2-d graphic, manipulator, tool MATLAB Answers — New Questions
Improving table loading time on App Designer for large dataset
I’m using a matlab script to evaluate data, format it in a table and store the result in a .mat file. Currently the table contains 2400×2034 data points but the final table would be 12000×2034 or larger.
The structure of the table is:
categorical(string), categorical(string), categorical(string), categorical(string), 1015xdouble, 1015xdouble
To display the data, I would like to build a simple app that would read the .mat file and display the whole or sections of table. However, the App Designer struggles even with small amounts of data. Displaying 8×2034 rows takes several seconds to load. With more entries, scrolling through the table causes stutters.
I have tried different version of .mat file with/without compression but unfortunately did not help.
The code to load the table at the startup-callback for the app:
% Code that executes after component creation
function startupFcn(app)
%If a completed Table already exists load it, otherwise create empty table
if isfile(‘completeTable.mat’)
load(‘completeTable.mat’);
end
app.completeTable = completeTable;
app.AvailableSpeciesListBox.Items = unique(app.completeTable.Shorthand);
end
And the code for loading the data into the table, upon selecting an entry in an itemlist:
% Value changed function: AvailableSpeciesListBox
function AvailableSpeciesListBoxValueChanged(app, event)
value = app.AvailableSpeciesListBox.Value;
selectedEntries = app.completeTable(app.completeTable.Shorthand == value,:);
app.UITable.Data = selectedEntries(:,2:width(app.completeTable));
endI’m using a matlab script to evaluate data, format it in a table and store the result in a .mat file. Currently the table contains 2400×2034 data points but the final table would be 12000×2034 or larger.
The structure of the table is:
categorical(string), categorical(string), categorical(string), categorical(string), 1015xdouble, 1015xdouble
To display the data, I would like to build a simple app that would read the .mat file and display the whole or sections of table. However, the App Designer struggles even with small amounts of data. Displaying 8×2034 rows takes several seconds to load. With more entries, scrolling through the table causes stutters.
I have tried different version of .mat file with/without compression but unfortunately did not help.
The code to load the table at the startup-callback for the app:
% Code that executes after component creation
function startupFcn(app)
%If a completed Table already exists load it, otherwise create empty table
if isfile(‘completeTable.mat’)
load(‘completeTable.mat’);
end
app.completeTable = completeTable;
app.AvailableSpeciesListBox.Items = unique(app.completeTable.Shorthand);
end
And the code for loading the data into the table, upon selecting an entry in an itemlist:
% Value changed function: AvailableSpeciesListBox
function AvailableSpeciesListBoxValueChanged(app, event)
value = app.AvailableSpeciesListBox.Value;
selectedEntries = app.completeTable(app.completeTable.Shorthand == value,:);
app.UITable.Data = selectedEntries(:,2:width(app.completeTable));
end I’m using a matlab script to evaluate data, format it in a table and store the result in a .mat file. Currently the table contains 2400×2034 data points but the final table would be 12000×2034 or larger.
The structure of the table is:
categorical(string), categorical(string), categorical(string), categorical(string), 1015xdouble, 1015xdouble
To display the data, I would like to build a simple app that would read the .mat file and display the whole or sections of table. However, the App Designer struggles even with small amounts of data. Displaying 8×2034 rows takes several seconds to load. With more entries, scrolling through the table causes stutters.
I have tried different version of .mat file with/without compression but unfortunately did not help.
The code to load the table at the startup-callback for the app:
% Code that executes after component creation
function startupFcn(app)
%If a completed Table already exists load it, otherwise create empty table
if isfile(‘completeTable.mat’)
load(‘completeTable.mat’);
end
app.completeTable = completeTable;
app.AvailableSpeciesListBox.Items = unique(app.completeTable.Shorthand);
end
And the code for loading the data into the table, upon selecting an entry in an itemlist:
% Value changed function: AvailableSpeciesListBox
function AvailableSpeciesListBoxValueChanged(app, event)
value = app.AvailableSpeciesListBox.Value;
selectedEntries = app.completeTable(app.completeTable.Shorthand == value,:);
app.UITable.Data = selectedEntries(:,2:width(app.completeTable));
end appdesigner, data import, uitable MATLAB Answers — New Questions
Changing the Topic Name in DDS Dictionary have no effect in AutoGenerated XML file
Hello, everyone. I want to create the DDS Application with DDS Blockset.
I have changed the Topic Name in DDS dictionary which was created from default dictionary.
However, when I examine the XML file which was generated automatically, I find that the Topic Names were still ‘Circle’ and ‘Square’.
Could anyone give some advice about how to change the Topic Name effectively?Hello, everyone. I want to create the DDS Application with DDS Blockset.
I have changed the Topic Name in DDS dictionary which was created from default dictionary.
However, when I examine the XML file which was generated automatically, I find that the Topic Names were still ‘Circle’ and ‘Square’.
Could anyone give some advice about how to change the Topic Name effectively? Hello, everyone. I want to create the DDS Application with DDS Blockset.
I have changed the Topic Name in DDS dictionary which was created from default dictionary.
However, when I examine the XML file which was generated automatically, I find that the Topic Names were still ‘Circle’ and ‘Square’.
Could anyone give some advice about how to change the Topic Name effectively? dds blockset, simulink, code generation MATLAB Answers — New Questions
Matlab spawn a lot of InstallMathWork process abnormally and cause system load too high
I’m trying out the example code from https://www.mathworks.com/help/5g/ug/nr-cell-search-and-mib-and-sib1-recovery.html from a remote ubuntu desktop through anydesk. At the same time I tried to edit the code inside vscode via ssh. The system load is not very high at most 2 and only use about one or two cores at the start, even I’m running the examples.
But after I have leave everything running there for quite a long time. There will automatically spawn a lot of InstallMathWork process, and the number of processes is gradually increasing. Eventually, it will have a lot of InstallMathWork process running in the background and eats up all the CPU cores, the system load increase to very high eventually.
I have checked that I’m already updated to the latest version manually and checked there’s no newer versions available. My current matlab version is R2024a Update 2 (24.1.0.2578822) 64 bit (glnxa64) April 9, 2024
Below is the screenshot from top and htop.I’m trying out the example code from https://www.mathworks.com/help/5g/ug/nr-cell-search-and-mib-and-sib1-recovery.html from a remote ubuntu desktop through anydesk. At the same time I tried to edit the code inside vscode via ssh. The system load is not very high at most 2 and only use about one or two cores at the start, even I’m running the examples.
But after I have leave everything running there for quite a long time. There will automatically spawn a lot of InstallMathWork process, and the number of processes is gradually increasing. Eventually, it will have a lot of InstallMathWork process running in the background and eats up all the CPU cores, the system load increase to very high eventually.
I have checked that I’m already updated to the latest version manually and checked there’s no newer versions available. My current matlab version is R2024a Update 2 (24.1.0.2578822) 64 bit (glnxa64) April 9, 2024
Below is the screenshot from top and htop. I’m trying out the example code from https://www.mathworks.com/help/5g/ug/nr-cell-search-and-mib-and-sib1-recovery.html from a remote ubuntu desktop through anydesk. At the same time I tried to edit the code inside vscode via ssh. The system load is not very high at most 2 and only use about one or two cores at the start, even I’m running the examples.
But after I have leave everything running there for quite a long time. There will automatically spawn a lot of InstallMathWork process, and the number of processes is gradually increasing. Eventually, it will have a lot of InstallMathWork process running in the background and eats up all the CPU cores, the system load increase to very high eventually.
I have checked that I’m already updated to the latest version manually and checked there’s no newer versions available. My current matlab version is R2024a Update 2 (24.1.0.2578822) 64 bit (glnxa64) April 9, 2024
Below is the screenshot from top and htop. load too high, installmathwork MATLAB Answers — New Questions
matlab union system generator, double-click the system generator module error
I am using matlab2019b, which is associated with vivado2019b. Today, I installed several toolboxes on matlab that I did not add before (using the original setup.exe file for installation), and when I was building the model, double-clicking the system generator module would cause an error
As shown in the picture below, how can I solve this problemI am using matlab2019b, which is associated with vivado2019b. Today, I installed several toolboxes on matlab that I did not add before (using the original setup.exe file for installation), and when I was building the model, double-clicking the system generator module would cause an error
As shown in the picture below, how can I solve this problem I am using matlab2019b, which is associated with vivado2019b. Today, I installed several toolboxes on matlab that I did not add before (using the original setup.exe file for installation), and when I was building the model, double-clicking the system generator module would cause an error
As shown in the picture below, how can I solve this problem simulink, system generator MATLAB Answers — New Questions
How to convert scilab code into matlab?
I have a code in Scilab. How to convert that code into Matlab?? Can anyone please tel me..I have a code in Scilab. How to convert that code into Matlab?? Can anyone please tel me.. I have a code in Scilab. How to convert that code into Matlab?? Can anyone please tel me.. scilab MATLAB Answers — New Questions
Why imwarp isn’t working for cylindrical projection?
I am trying to find the cylindrical projection of an image using the cylindrical projection equations. After finding the warpped values for the X and Y corodinates, I am trying to use the inbuilt MATLAB imwarp function to project the image onto the new coordinates, so that I can use the interpolation for smooth image. However, I get a different warpped image. Here is the output what I am getting:
What I expect the image to be:
Below is the cylindrical projection code:
clc; close all; clear;
% Inputs
fileName = ‘checker.jpg’;
% Focal lengths
fx = 50;
fy = 50;
% Read image
image = (imread(fileName));
% Get image size
[ydim, xdim, bypixs] = size(image);
% Camera intrinsics
K = [fx, 0, xdim/2; 0, fy, ydim/2; 0, 0, 1];
% Distortion coefficients [k1, k2, k3, p1, p2]
DC = [0, 0, 0, 0, 0];
% Get distrotion coefficients
fx = K(1,1);
fy = K(2,2);
k1 = DC(1);
k2 = DC(2);
k3 = DC(3);
p1 = DC(4);
p2 = DC(5);
% Get image size
[ydim, xdim, bypixs] = size(image);
% Get the center of image
xc = xdim/2;
yc = ydim/2;
% Create X and Y coordinates grid
[X,Y] = meshgrid(1:xdim, 1:ydim);
% Perform the cylindrical projection
theta = (X – xc) / fx;
h = (Y – yc) / fy;
% Cylindrical coordinates to Cartesian
xcap = sin(theta);
ycap = h;
zcap = cos(theta);
xyz_cap = cat(3, xcap, ycap, zcap);
xyz_cap = reshape(xyz_cap,[],3);
% Normalized coords
xyz_cap_norm = (K * xyz_cap’)’;
xn = xyz_cap_norm(:,1) ./ xyz_cap_norm(:,3);
yn = xyz_cap_norm(:,2) ./ xyz_cap_norm(:,3);
% Radial and tangential distortion
r = xn.^2 + yn.^2;
xd_r = xn .* (1 + k1 * r.^2 + k2 * r.^4 + k3 * r.^6);
yd_r = yn .* (1 + k1 * r.^2 + k2 * r.^4 + k3 * r.^6);
xd_t = 2 * p1 * xn .* yn + p2 * (r.^2 + 2 * xn.^2);
yd_t = p1 * (r.^2 + 2 * yn.^2) + 2 * p2 * xn .* yn;
xd = xd_r + xd_t;
yd = yd_r + yd_t;
% Convert to 2D array
xd = reshape(ceil(xd),[ydim, xdim]);
yd = reshape(ceil(yd),[ydim, xdim]);
% Get projections
imageCylindrical = imwarp(image, cat(3,xd, yd), ‘cubic’);
imshow(imageCylindrical)
Please let me know what I am doing wrong using the imwarp function. Any help is appreciated!I am trying to find the cylindrical projection of an image using the cylindrical projection equations. After finding the warpped values for the X and Y corodinates, I am trying to use the inbuilt MATLAB imwarp function to project the image onto the new coordinates, so that I can use the interpolation for smooth image. However, I get a different warpped image. Here is the output what I am getting:
What I expect the image to be:
Below is the cylindrical projection code:
clc; close all; clear;
% Inputs
fileName = ‘checker.jpg’;
% Focal lengths
fx = 50;
fy = 50;
% Read image
image = (imread(fileName));
% Get image size
[ydim, xdim, bypixs] = size(image);
% Camera intrinsics
K = [fx, 0, xdim/2; 0, fy, ydim/2; 0, 0, 1];
% Distortion coefficients [k1, k2, k3, p1, p2]
DC = [0, 0, 0, 0, 0];
% Get distrotion coefficients
fx = K(1,1);
fy = K(2,2);
k1 = DC(1);
k2 = DC(2);
k3 = DC(3);
p1 = DC(4);
p2 = DC(5);
% Get image size
[ydim, xdim, bypixs] = size(image);
% Get the center of image
xc = xdim/2;
yc = ydim/2;
% Create X and Y coordinates grid
[X,Y] = meshgrid(1:xdim, 1:ydim);
% Perform the cylindrical projection
theta = (X – xc) / fx;
h = (Y – yc) / fy;
% Cylindrical coordinates to Cartesian
xcap = sin(theta);
ycap = h;
zcap = cos(theta);
xyz_cap = cat(3, xcap, ycap, zcap);
xyz_cap = reshape(xyz_cap,[],3);
% Normalized coords
xyz_cap_norm = (K * xyz_cap’)’;
xn = xyz_cap_norm(:,1) ./ xyz_cap_norm(:,3);
yn = xyz_cap_norm(:,2) ./ xyz_cap_norm(:,3);
% Radial and tangential distortion
r = xn.^2 + yn.^2;
xd_r = xn .* (1 + k1 * r.^2 + k2 * r.^4 + k3 * r.^6);
yd_r = yn .* (1 + k1 * r.^2 + k2 * r.^4 + k3 * r.^6);
xd_t = 2 * p1 * xn .* yn + p2 * (r.^2 + 2 * xn.^2);
yd_t = p1 * (r.^2 + 2 * yn.^2) + 2 * p2 * xn .* yn;
xd = xd_r + xd_t;
yd = yd_r + yd_t;
% Convert to 2D array
xd = reshape(ceil(xd),[ydim, xdim]);
yd = reshape(ceil(yd),[ydim, xdim]);
% Get projections
imageCylindrical = imwarp(image, cat(3,xd, yd), ‘cubic’);
imshow(imageCylindrical)
Please let me know what I am doing wrong using the imwarp function. Any help is appreciated! I am trying to find the cylindrical projection of an image using the cylindrical projection equations. After finding the warpped values for the X and Y corodinates, I am trying to use the inbuilt MATLAB imwarp function to project the image onto the new coordinates, so that I can use the interpolation for smooth image. However, I get a different warpped image. Here is the output what I am getting:
What I expect the image to be:
Below is the cylindrical projection code:
clc; close all; clear;
% Inputs
fileName = ‘checker.jpg’;
% Focal lengths
fx = 50;
fy = 50;
% Read image
image = (imread(fileName));
% Get image size
[ydim, xdim, bypixs] = size(image);
% Camera intrinsics
K = [fx, 0, xdim/2; 0, fy, ydim/2; 0, 0, 1];
% Distortion coefficients [k1, k2, k3, p1, p2]
DC = [0, 0, 0, 0, 0];
% Get distrotion coefficients
fx = K(1,1);
fy = K(2,2);
k1 = DC(1);
k2 = DC(2);
k3 = DC(3);
p1 = DC(4);
p2 = DC(5);
% Get image size
[ydim, xdim, bypixs] = size(image);
% Get the center of image
xc = xdim/2;
yc = ydim/2;
% Create X and Y coordinates grid
[X,Y] = meshgrid(1:xdim, 1:ydim);
% Perform the cylindrical projection
theta = (X – xc) / fx;
h = (Y – yc) / fy;
% Cylindrical coordinates to Cartesian
xcap = sin(theta);
ycap = h;
zcap = cos(theta);
xyz_cap = cat(3, xcap, ycap, zcap);
xyz_cap = reshape(xyz_cap,[],3);
% Normalized coords
xyz_cap_norm = (K * xyz_cap’)’;
xn = xyz_cap_norm(:,1) ./ xyz_cap_norm(:,3);
yn = xyz_cap_norm(:,2) ./ xyz_cap_norm(:,3);
% Radial and tangential distortion
r = xn.^2 + yn.^2;
xd_r = xn .* (1 + k1 * r.^2 + k2 * r.^4 + k3 * r.^6);
yd_r = yn .* (1 + k1 * r.^2 + k2 * r.^4 + k3 * r.^6);
xd_t = 2 * p1 * xn .* yn + p2 * (r.^2 + 2 * xn.^2);
yd_t = p1 * (r.^2 + 2 * yn.^2) + 2 * p2 * xn .* yn;
xd = xd_r + xd_t;
yd = yd_r + yd_t;
% Convert to 2D array
xd = reshape(ceil(xd),[ydim, xdim]);
yd = reshape(ceil(yd),[ydim, xdim]);
% Get projections
imageCylindrical = imwarp(image, cat(3,xd, yd), ‘cubic’);
imshow(imageCylindrical)
Please let me know what I am doing wrong using the imwarp function. Any help is appreciated! matlab, imwarp, image processing MATLAB Answers — New Questions
Why is this While Loop not running?
Hi all,
I’m doing a spacecraft link budget analysis in MATLAB. I have a function that calculates the link margin, which I call in a main script. As I wish to limit the margin to a certain range I use a While Loop that alters the transmission power (P_t) until the condition is satisfied.
P_t=5;
flag_para=0;
flag_helix=0;
flag_horn=0;
flag_array=1;
S=S_epsilon*1000;
R_b=20e+6;
BER=8e-6;
dl=3;
A=0.1; % phase array
D_t=0; % Parabolic
eta=0.7;
f_t=8e+9;
lamda=3e+8/f_t; % Operating Wavelength in metres
L_com=0; % horn
margin=-inf;
j=1;
while margin<6 && margin>12
[margin,M_com,P_com,L_ant]=comm_payload(flag_para,flag_helix,flag_horn,flag_array…
,P_t,eta,lamda,D_t,f_t,L_com,A,S,dl,R_b,BER);
if margin<6
P_t=P_t*1.1;
j=j+1;
elseif margin>12
P_t=P_t*0.9;
j=j+1;
end
end
This doesn’t seem to be working. The code runs but J stays at 1 and the margin also remains at -inf. Any ideas what is wrong? The function 100% works, tested it many times without the while loop.
CheersHi all,
I’m doing a spacecraft link budget analysis in MATLAB. I have a function that calculates the link margin, which I call in a main script. As I wish to limit the margin to a certain range I use a While Loop that alters the transmission power (P_t) until the condition is satisfied.
P_t=5;
flag_para=0;
flag_helix=0;
flag_horn=0;
flag_array=1;
S=S_epsilon*1000;
R_b=20e+6;
BER=8e-6;
dl=3;
A=0.1; % phase array
D_t=0; % Parabolic
eta=0.7;
f_t=8e+9;
lamda=3e+8/f_t; % Operating Wavelength in metres
L_com=0; % horn
margin=-inf;
j=1;
while margin<6 && margin>12
[margin,M_com,P_com,L_ant]=comm_payload(flag_para,flag_helix,flag_horn,flag_array…
,P_t,eta,lamda,D_t,f_t,L_com,A,S,dl,R_b,BER);
if margin<6
P_t=P_t*1.1;
j=j+1;
elseif margin>12
P_t=P_t*0.9;
j=j+1;
end
end
This doesn’t seem to be working. The code runs but J stays at 1 and the margin also remains at -inf. Any ideas what is wrong? The function 100% works, tested it many times without the while loop.
Cheers Hi all,
I’m doing a spacecraft link budget analysis in MATLAB. I have a function that calculates the link margin, which I call in a main script. As I wish to limit the margin to a certain range I use a While Loop that alters the transmission power (P_t) until the condition is satisfied.
P_t=5;
flag_para=0;
flag_helix=0;
flag_horn=0;
flag_array=1;
S=S_epsilon*1000;
R_b=20e+6;
BER=8e-6;
dl=3;
A=0.1; % phase array
D_t=0; % Parabolic
eta=0.7;
f_t=8e+9;
lamda=3e+8/f_t; % Operating Wavelength in metres
L_com=0; % horn
margin=-inf;
j=1;
while margin<6 && margin>12
[margin,M_com,P_com,L_ant]=comm_payload(flag_para,flag_helix,flag_horn,flag_array…
,P_t,eta,lamda,D_t,f_t,L_com,A,S,dl,R_b,BER);
if margin<6
P_t=P_t*1.1;
j=j+1;
elseif margin>12
P_t=P_t*0.9;
j=j+1;
end
end
This doesn’t seem to be working. The code runs but J stays at 1 and the margin also remains at -inf. Any ideas what is wrong? The function 100% works, tested it many times without the while loop.
Cheers while loop MATLAB Answers — New Questions
How to create histograms for L a b channels separately in CIELAB color space.
How to create histograms for L a b channels separately in CIELAB color space.How to create histograms for L a b channels separately in CIELAB color space. How to create histograms for L a b channels separately in CIELAB color space. color space, cielab MATLAB Answers — New Questions
Runge Kutta 4th Order Method for an Equation
The following is an supercritical CO2 equation of an oil from leaves:
Where
W = CO2 Mass flowrate (constant)
ρ = solvent density (constant)
ϵ = bed porosity (constant)
V = extrtactor volume (constant)
ti = internal diffusion diameter (constant)
n = number of stages (desired to reach a stage of 10 hence n starts at 1 and ends at 10)
Cn = fluid phase concentration in the nth stage
Cn_bar = solid phase concentration in the nth phase
Cn_bar* = Cn/0.2
The inital conditions are t = 0, Cn = 0 and Cn_bar = 0
I would like to know what is the best way to set up the equation and code in order for it execute the 4th order runge kutta method on Matlab so as to achieve Cn at the 10th stage. Also note the initial oil concentration in the solid phase was 9.0 kg/m3. This is the code that was developed so far, however it is not running.
clear; clc;
% Parameters
h = 20; % Step size
tfinal = 500; % Solve from t=(0,tfinal)
e = 0.38; % Bed porosity
rho = 126; % Solvent (CO2) density
W = 0.95; % CO2 flow rate, kg/h
V = 0.0004; % Extractor volume, m^3
Di = 6 * 10^-13; % Diffusion coefficient
n = 10; % Number of stages/bed divisions
ti = 1736.111; % Internal diffusion time
% Initial Condition
t(1) = 0;
c(1) = 0;
cbar(1) = 9;
c_in(1) = 0;
% Define the ODE functions
f1 = @(t,c,cbar) -1/ti * (cbar – c/0.2);
f2 = @(t,c,cbar) -(((1 – e) * V/n * f1(t,c,cbar)) + W/rho * (c – c_in))/e * V/n;
% RK4 Loop for 9 iterations
for iter = 1:10
% RK4 Loop for solving ODEs
for i = 1:ceil(tfinal/h)
t(i+1) = t(i) + h;
% Update cbar
k1_1 = f1(t(i), c(i), cbar(i));
k2_1 = f1(t(i) + 0.5*h, c(i) + 0.5*h*k1_1, cbar(i) + 0.5*h*k1_1);
k3_1 = f1(t(i) + 0.5*h, c(i) + 0.5*h*k2_1, cbar(i) + 0.5*h*k2_1);
k4_1 = f1(t(i) + h, c(i) + h*k3_1, cbar(i) + h*k3_1);
cbar(i+1) = cbar(i) + h/6*(k1_1 + 2*k2_1 + 2*k3_1 + k4_1);
% Update c
k1_2 = f2(t(i), c(i), cbar(i));
k2_2 = f2(t(i) + 0.5*h, c(i) + 0.5*h*k1_2, cbar(i));
k3_2 = f2(t(i) + 0.5*h, c(i) + 0.5*h*k2_2, cbar(i));
k4_2 = f2(t(i) + h, c(i) + h*k3_2, cbar(i));
c(i+1) = c(i) + h/6*(k1_2 + 2*k2_2 + 2*k3_2 + k4_2);
end
% Update initial values for next iteration
c(1) = c(end);
cbar(1) = cbar(end);
% Display iteration number and updated initial values
disp([‘Iteration ‘, num2str(iter), ‘: c(1) = ‘, num2str(c(1)), ‘, cbar(1) = ‘, num2str(cbar(1))]);
end
plot(t,c)
xlabel(‘t’)
ylabel(‘c’)
set(gca,’Fontsize’,16)The following is an supercritical CO2 equation of an oil from leaves:
Where
W = CO2 Mass flowrate (constant)
ρ = solvent density (constant)
ϵ = bed porosity (constant)
V = extrtactor volume (constant)
ti = internal diffusion diameter (constant)
n = number of stages (desired to reach a stage of 10 hence n starts at 1 and ends at 10)
Cn = fluid phase concentration in the nth stage
Cn_bar = solid phase concentration in the nth phase
Cn_bar* = Cn/0.2
The inital conditions are t = 0, Cn = 0 and Cn_bar = 0
I would like to know what is the best way to set up the equation and code in order for it execute the 4th order runge kutta method on Matlab so as to achieve Cn at the 10th stage. Also note the initial oil concentration in the solid phase was 9.0 kg/m3. This is the code that was developed so far, however it is not running.
clear; clc;
% Parameters
h = 20; % Step size
tfinal = 500; % Solve from t=(0,tfinal)
e = 0.38; % Bed porosity
rho = 126; % Solvent (CO2) density
W = 0.95; % CO2 flow rate, kg/h
V = 0.0004; % Extractor volume, m^3
Di = 6 * 10^-13; % Diffusion coefficient
n = 10; % Number of stages/bed divisions
ti = 1736.111; % Internal diffusion time
% Initial Condition
t(1) = 0;
c(1) = 0;
cbar(1) = 9;
c_in(1) = 0;
% Define the ODE functions
f1 = @(t,c,cbar) -1/ti * (cbar – c/0.2);
f2 = @(t,c,cbar) -(((1 – e) * V/n * f1(t,c,cbar)) + W/rho * (c – c_in))/e * V/n;
% RK4 Loop for 9 iterations
for iter = 1:10
% RK4 Loop for solving ODEs
for i = 1:ceil(tfinal/h)
t(i+1) = t(i) + h;
% Update cbar
k1_1 = f1(t(i), c(i), cbar(i));
k2_1 = f1(t(i) + 0.5*h, c(i) + 0.5*h*k1_1, cbar(i) + 0.5*h*k1_1);
k3_1 = f1(t(i) + 0.5*h, c(i) + 0.5*h*k2_1, cbar(i) + 0.5*h*k2_1);
k4_1 = f1(t(i) + h, c(i) + h*k3_1, cbar(i) + h*k3_1);
cbar(i+1) = cbar(i) + h/6*(k1_1 + 2*k2_1 + 2*k3_1 + k4_1);
% Update c
k1_2 = f2(t(i), c(i), cbar(i));
k2_2 = f2(t(i) + 0.5*h, c(i) + 0.5*h*k1_2, cbar(i));
k3_2 = f2(t(i) + 0.5*h, c(i) + 0.5*h*k2_2, cbar(i));
k4_2 = f2(t(i) + h, c(i) + h*k3_2, cbar(i));
c(i+1) = c(i) + h/6*(k1_2 + 2*k2_2 + 2*k3_2 + k4_2);
end
% Update initial values for next iteration
c(1) = c(end);
cbar(1) = cbar(end);
% Display iteration number and updated initial values
disp([‘Iteration ‘, num2str(iter), ‘: c(1) = ‘, num2str(c(1)), ‘, cbar(1) = ‘, num2str(cbar(1))]);
end
plot(t,c)
xlabel(‘t’)
ylabel(‘c’)
set(gca,’Fontsize’,16) The following is an supercritical CO2 equation of an oil from leaves:
Where
W = CO2 Mass flowrate (constant)
ρ = solvent density (constant)
ϵ = bed porosity (constant)
V = extrtactor volume (constant)
ti = internal diffusion diameter (constant)
n = number of stages (desired to reach a stage of 10 hence n starts at 1 and ends at 10)
Cn = fluid phase concentration in the nth stage
Cn_bar = solid phase concentration in the nth phase
Cn_bar* = Cn/0.2
The inital conditions are t = 0, Cn = 0 and Cn_bar = 0
I would like to know what is the best way to set up the equation and code in order for it execute the 4th order runge kutta method on Matlab so as to achieve Cn at the 10th stage. Also note the initial oil concentration in the solid phase was 9.0 kg/m3. This is the code that was developed so far, however it is not running.
clear; clc;
% Parameters
h = 20; % Step size
tfinal = 500; % Solve from t=(0,tfinal)
e = 0.38; % Bed porosity
rho = 126; % Solvent (CO2) density
W = 0.95; % CO2 flow rate, kg/h
V = 0.0004; % Extractor volume, m^3
Di = 6 * 10^-13; % Diffusion coefficient
n = 10; % Number of stages/bed divisions
ti = 1736.111; % Internal diffusion time
% Initial Condition
t(1) = 0;
c(1) = 0;
cbar(1) = 9;
c_in(1) = 0;
% Define the ODE functions
f1 = @(t,c,cbar) -1/ti * (cbar – c/0.2);
f2 = @(t,c,cbar) -(((1 – e) * V/n * f1(t,c,cbar)) + W/rho * (c – c_in))/e * V/n;
% RK4 Loop for 9 iterations
for iter = 1:10
% RK4 Loop for solving ODEs
for i = 1:ceil(tfinal/h)
t(i+1) = t(i) + h;
% Update cbar
k1_1 = f1(t(i), c(i), cbar(i));
k2_1 = f1(t(i) + 0.5*h, c(i) + 0.5*h*k1_1, cbar(i) + 0.5*h*k1_1);
k3_1 = f1(t(i) + 0.5*h, c(i) + 0.5*h*k2_1, cbar(i) + 0.5*h*k2_1);
k4_1 = f1(t(i) + h, c(i) + h*k3_1, cbar(i) + h*k3_1);
cbar(i+1) = cbar(i) + h/6*(k1_1 + 2*k2_1 + 2*k3_1 + k4_1);
% Update c
k1_2 = f2(t(i), c(i), cbar(i));
k2_2 = f2(t(i) + 0.5*h, c(i) + 0.5*h*k1_2, cbar(i));
k3_2 = f2(t(i) + 0.5*h, c(i) + 0.5*h*k2_2, cbar(i));
k4_2 = f2(t(i) + h, c(i) + h*k3_2, cbar(i));
c(i+1) = c(i) + h/6*(k1_2 + 2*k2_2 + 2*k3_2 + k4_2);
end
% Update initial values for next iteration
c(1) = c(end);
cbar(1) = cbar(end);
% Display iteration number and updated initial values
disp([‘Iteration ‘, num2str(iter), ‘: c(1) = ‘, num2str(c(1)), ‘, cbar(1) = ‘, num2str(cbar(1))]);
end
plot(t,c)
xlabel(‘t’)
ylabel(‘c’)
set(gca,’Fontsize’,16) runge kutta, 4th order, supercritical co2 extraction, oil extraction MATLAB Answers — New Questions
Optimal weights using outer optimization loop
How to optimize weights in the following problem:
a[100],b[100],c[100],w1,w2,w3;
f = w1*a+w2*b+w3*c;
for 1:100
{
fmincon (minimize(f) w.r.t a[i],b[i],c[i]) with one weight[w1,w2,w3](user defined)
}
after 100 values calculation is done:
X = [avg_a,avg_b,avg_c]
the sample code is as follows:
% Loop through each theta value
for i = 1:length(range)
% Solve for the current theta
[solution, objectiveValue] = fmincon(@(x) objectiveFcn(x, range(i),weights), initial_guess, [], [], [], [], lb, ub, @(x) constraintFcn(x, range(i)), options2);
% Display the value of the objective function in each iteration
disp([‘Iteration ‘, num2str(i), ‘: Objective Value = ‘, num2str(objectiveValue)]);
% Store solution and objective value
solutions(i, 🙂 = solution;
objective_values(i) = objectiveValue;
end
after this we have the average.
All this code mentioned works good….
objective for weight: change weights to minimize the max of X[avg_a,avg_b,avg_c]
The problem or issue I have right now is if i try to use outer fmincon or fminsearch for weights as X is just a scaler number so i dont understand how to create a second loop for weights(outer loop).
Am i thinking of the problem correctly? or any other methods that i can look into would also help like hill climb etc.How to optimize weights in the following problem:
a[100],b[100],c[100],w1,w2,w3;
f = w1*a+w2*b+w3*c;
for 1:100
{
fmincon (minimize(f) w.r.t a[i],b[i],c[i]) with one weight[w1,w2,w3](user defined)
}
after 100 values calculation is done:
X = [avg_a,avg_b,avg_c]
the sample code is as follows:
% Loop through each theta value
for i = 1:length(range)
% Solve for the current theta
[solution, objectiveValue] = fmincon(@(x) objectiveFcn(x, range(i),weights), initial_guess, [], [], [], [], lb, ub, @(x) constraintFcn(x, range(i)), options2);
% Display the value of the objective function in each iteration
disp([‘Iteration ‘, num2str(i), ‘: Objective Value = ‘, num2str(objectiveValue)]);
% Store solution and objective value
solutions(i, 🙂 = solution;
objective_values(i) = objectiveValue;
end
after this we have the average.
All this code mentioned works good….
objective for weight: change weights to minimize the max of X[avg_a,avg_b,avg_c]
The problem or issue I have right now is if i try to use outer fmincon or fminsearch for weights as X is just a scaler number so i dont understand how to create a second loop for weights(outer loop).
Am i thinking of the problem correctly? or any other methods that i can look into would also help like hill climb etc. How to optimize weights in the following problem:
a[100],b[100],c[100],w1,w2,w3;
f = w1*a+w2*b+w3*c;
for 1:100
{
fmincon (minimize(f) w.r.t a[i],b[i],c[i]) with one weight[w1,w2,w3](user defined)
}
after 100 values calculation is done:
X = [avg_a,avg_b,avg_c]
the sample code is as follows:
% Loop through each theta value
for i = 1:length(range)
% Solve for the current theta
[solution, objectiveValue] = fmincon(@(x) objectiveFcn(x, range(i),weights), initial_guess, [], [], [], [], lb, ub, @(x) constraintFcn(x, range(i)), options2);
% Display the value of the objective function in each iteration
disp([‘Iteration ‘, num2str(i), ‘: Objective Value = ‘, num2str(objectiveValue)]);
% Store solution and objective value
solutions(i, 🙂 = solution;
objective_values(i) = objectiveValue;
end
after this we have the average.
All this code mentioned works good….
objective for weight: change weights to minimize the max of X[avg_a,avg_b,avg_c]
The problem or issue I have right now is if i try to use outer fmincon or fminsearch for weights as X is just a scaler number so i dont understand how to create a second loop for weights(outer loop).
Am i thinking of the problem correctly? or any other methods that i can look into would also help like hill climb etc. optimization, fmincon, search MATLAB Answers — New Questions