Category: Matlab
Category Archives: Matlab
How to enable BitMask in EcuDescriptions when using coder.asap2.export
I have created CSC for measurement signals and I am packing my signals as bitfield. My generated code has all signals declared inside a structure with bitwidth. when I use coder.asap2.export to generate a2l file, Measurement has no BitMAsk Information.
With Matlab 2023b, I tried to extract EcuDescriptions using command descObj = coder.asap2.getEcuDescriptions("ModelName") and then I tried to extract measurement properties using command get(descObj,"Measurement","Struct.Signal1"). Measurement object has no information on BitMask.
Can someone guide me how to configure my model so that BitMAsk information is present in my a2l file?I have created CSC for measurement signals and I am packing my signals as bitfield. My generated code has all signals declared inside a structure with bitwidth. when I use coder.asap2.export to generate a2l file, Measurement has no BitMAsk Information.
With Matlab 2023b, I tried to extract EcuDescriptions using command descObj = coder.asap2.getEcuDescriptions("ModelName") and then I tried to extract measurement properties using command get(descObj,"Measurement","Struct.Signal1"). Measurement object has no information on BitMask.
Can someone guide me how to configure my model so that BitMAsk information is present in my a2l file? I have created CSC for measurement signals and I am packing my signals as bitfield. My generated code has all signals declared inside a structure with bitwidth. when I use coder.asap2.export to generate a2l file, Measurement has no BitMAsk Information.
With Matlab 2023b, I tried to extract EcuDescriptions using command descObj = coder.asap2.getEcuDescriptions("ModelName") and then I tried to extract measurement properties using command get(descObj,"Measurement","Struct.Signal1"). Measurement object has no information on BitMask.
Can someone guide me how to configure my model so that BitMAsk information is present in my a2l file? asap2, embedded coder MATLAB Answers — New Questions
how to plot a matrix graph of D(n,m) versus C(n,m) with different colors
I would like to plot a graph of D versus C. For each i have a different colorI would like to plot a graph of D versus C. For each i have a different color I would like to plot a graph of D versus C. For each i have a different color matrix, plot, color MATLAB Answers — New Questions
Optimize the constant by minimizing the error whit no direct relation
I want to find the optimised value for the three constant C1, C2, C3 by minimising the error of ErFEM.
I run an ABAQUS job; in the first job, I define C1, C2, C3, and the ABAQUS generates a result, let’s name it FEMresutl.
I subtract the FEMresult from the gold standard, and the final result is ErFEM.
ErFEM should become less than 50um by optimising C1, C2, C3.
However, there is no direct relation between the ErFEM and C1, C2, and C3.
How can I write an optimisation code that optimises the C1, C2, C3 by minimising the ErFEM?
ThanksI want to find the optimised value for the three constant C1, C2, C3 by minimising the error of ErFEM.
I run an ABAQUS job; in the first job, I define C1, C2, C3, and the ABAQUS generates a result, let’s name it FEMresutl.
I subtract the FEMresult from the gold standard, and the final result is ErFEM.
ErFEM should become less than 50um by optimising C1, C2, C3.
However, there is no direct relation between the ErFEM and C1, C2, and C3.
How can I write an optimisation code that optimises the C1, C2, C3 by minimising the ErFEM?
Thanks I want to find the optimised value for the three constant C1, C2, C3 by minimising the error of ErFEM.
I run an ABAQUS job; in the first job, I define C1, C2, C3, and the ABAQUS generates a result, let’s name it FEMresutl.
I subtract the FEMresult from the gold standard, and the final result is ErFEM.
ErFEM should become less than 50um by optimising C1, C2, C3.
However, there is no direct relation between the ErFEM and C1, C2, and C3.
How can I write an optimisation code that optimises the C1, C2, C3 by minimising the ErFEM?
Thanks optimization MATLAB Answers — New Questions
Help with contour plot
Hello veryone,
i am trying do a contour plot of the stability of a mechanical system: so given a meshgrid X-Y and for a varying parameter k1, i calculate Z based on two conditions (B and D) and plot for Z=0. As k1 can be one of five different values i would like to have five different curves on the same plot.
but i only get two curves (which are also not right) and in the command windows this warning appears:
"Warning: Contour not rendered for constant ZData"
could anybody help me find the problem? thank you very much
here ist the script i am using
clear; clc; clf;
M = 700; J = 400; a1 = 1.85; a2 = 1.85; L = 3.7;
n = 101;
m = 50000;
k_a12 = linspace(-m, m, n);
k_a21 = linspace(-m, m, n);
[X, Y] = meshgrid(k_a12, k_a21);
v = [0 0];
clr = [‘r’,’g’,’b’,’c’,’k’];
b = 100000;
a = 5;
k1 = linspace(-b, b, a);
k2 = 0;
LegendsStrings = cell(numel(k1),1);
Z = zeros(n, n);
for q = 1:a
for i = 1:n
for j = 1:n
B = k1(q)*(J + M*a1^2) + k2*(J + M*a2^2) + (X + Y)*(J – M*a1*a2);
D = k1(q)*k2 – X.*Y;
if B(i, j) >= 0 && D(i, j) >= 0
Z(i, j) = D(i, j);
else
Z(i, j) = -1;
end
end
end
LegendsStrings{q} = [‘k_1 = ‘, num2str(k1(q))];
contour(X, Y, Z, v, ‘LineWidth’, 1.2, ‘LineColor’, clr(q), ‘DisplayName’, LegendsStrings{q});
hold on
end
legend()
xlabel(‘k_a_1_2’)
ylabel(‘k_a_2_1’)
grid onHello veryone,
i am trying do a contour plot of the stability of a mechanical system: so given a meshgrid X-Y and for a varying parameter k1, i calculate Z based on two conditions (B and D) and plot for Z=0. As k1 can be one of five different values i would like to have five different curves on the same plot.
but i only get two curves (which are also not right) and in the command windows this warning appears:
"Warning: Contour not rendered for constant ZData"
could anybody help me find the problem? thank you very much
here ist the script i am using
clear; clc; clf;
M = 700; J = 400; a1 = 1.85; a2 = 1.85; L = 3.7;
n = 101;
m = 50000;
k_a12 = linspace(-m, m, n);
k_a21 = linspace(-m, m, n);
[X, Y] = meshgrid(k_a12, k_a21);
v = [0 0];
clr = [‘r’,’g’,’b’,’c’,’k’];
b = 100000;
a = 5;
k1 = linspace(-b, b, a);
k2 = 0;
LegendsStrings = cell(numel(k1),1);
Z = zeros(n, n);
for q = 1:a
for i = 1:n
for j = 1:n
B = k1(q)*(J + M*a1^2) + k2*(J + M*a2^2) + (X + Y)*(J – M*a1*a2);
D = k1(q)*k2 – X.*Y;
if B(i, j) >= 0 && D(i, j) >= 0
Z(i, j) = D(i, j);
else
Z(i, j) = -1;
end
end
end
LegendsStrings{q} = [‘k_1 = ‘, num2str(k1(q))];
contour(X, Y, Z, v, ‘LineWidth’, 1.2, ‘LineColor’, clr(q), ‘DisplayName’, LegendsStrings{q});
hold on
end
legend()
xlabel(‘k_a_1_2’)
ylabel(‘k_a_2_1’)
grid on Hello veryone,
i am trying do a contour plot of the stability of a mechanical system: so given a meshgrid X-Y and for a varying parameter k1, i calculate Z based on two conditions (B and D) and plot for Z=0. As k1 can be one of five different values i would like to have five different curves on the same plot.
but i only get two curves (which are also not right) and in the command windows this warning appears:
"Warning: Contour not rendered for constant ZData"
could anybody help me find the problem? thank you very much
here ist the script i am using
clear; clc; clf;
M = 700; J = 400; a1 = 1.85; a2 = 1.85; L = 3.7;
n = 101;
m = 50000;
k_a12 = linspace(-m, m, n);
k_a21 = linspace(-m, m, n);
[X, Y] = meshgrid(k_a12, k_a21);
v = [0 0];
clr = [‘r’,’g’,’b’,’c’,’k’];
b = 100000;
a = 5;
k1 = linspace(-b, b, a);
k2 = 0;
LegendsStrings = cell(numel(k1),1);
Z = zeros(n, n);
for q = 1:a
for i = 1:n
for j = 1:n
B = k1(q)*(J + M*a1^2) + k2*(J + M*a2^2) + (X + Y)*(J – M*a1*a2);
D = k1(q)*k2 – X.*Y;
if B(i, j) >= 0 && D(i, j) >= 0
Z(i, j) = D(i, j);
else
Z(i, j) = -1;
end
end
end
LegendsStrings{q} = [‘k_1 = ‘, num2str(k1(q))];
contour(X, Y, Z, v, ‘LineWidth’, 1.2, ‘LineColor’, clr(q), ‘DisplayName’, LegendsStrings{q});
hold on
end
legend()
xlabel(‘k_a_1_2’)
ylabel(‘k_a_2_1’)
grid on contour, 2d plot, loops, contour plot MATLAB Answers — New Questions
How to include requirements in Embedded Web View Report
I have searched the forums, Google and the documentation for hours, but i cannot find a way to include the requirements in an Embedded Web View Report. My MATLAB version is R2024a.
While it is easy to include the requirements when generating an standard webview form Simulink (see image below), it does not seem to be possible to do so with code in Embedded Web View Report generation.
The following code belongs to the class that i am using to generate this report (it is worth mentioning that there are no issues here, the report is correctly generated):
function rpt = classReportGeneratorWebview(reportName,modelName)
rpt@slreportgen.webview.EmbeddedWebViewDocument(…
reportName,modelName);
% Suppress Link Warning Messages for Embedded Web View Reports:
rpt.ValidateLinksAndAnchors = false;
% Specify Export Options for Embedded Web View Reports:
rpt.ExportOptions.SearchScope = ‘All’;
rpt.ExportOptions.IncludeReferencedModels = true;
rpt.ExportOptions.IncludeMaskedSubsystems = true;
end
As can be seen, the ExportOptions has properties that allow including multiple aspects. However, in the documentation (https://es.mathworks.com/help/rptgenext/ug/slreportgen.webview.exportoptions-class.html), there is no property related to including the requirements.
Therefore, when the report is generated, the button that allows access to the requirements view is obviously missing.
I would like to know if there is a way to include requirements in an Embedded Web View Report, inside the webview. Help would be much appreciated.I have searched the forums, Google and the documentation for hours, but i cannot find a way to include the requirements in an Embedded Web View Report. My MATLAB version is R2024a.
While it is easy to include the requirements when generating an standard webview form Simulink (see image below), it does not seem to be possible to do so with code in Embedded Web View Report generation.
The following code belongs to the class that i am using to generate this report (it is worth mentioning that there are no issues here, the report is correctly generated):
function rpt = classReportGeneratorWebview(reportName,modelName)
rpt@slreportgen.webview.EmbeddedWebViewDocument(…
reportName,modelName);
% Suppress Link Warning Messages for Embedded Web View Reports:
rpt.ValidateLinksAndAnchors = false;
% Specify Export Options for Embedded Web View Reports:
rpt.ExportOptions.SearchScope = ‘All’;
rpt.ExportOptions.IncludeReferencedModels = true;
rpt.ExportOptions.IncludeMaskedSubsystems = true;
end
As can be seen, the ExportOptions has properties that allow including multiple aspects. However, in the documentation (https://es.mathworks.com/help/rptgenext/ug/slreportgen.webview.exportoptions-class.html), there is no property related to including the requirements.
Therefore, when the report is generated, the button that allows access to the requirements view is obviously missing.
I would like to know if there is a way to include requirements in an Embedded Web View Report, inside the webview. Help would be much appreciated. I have searched the forums, Google and the documentation for hours, but i cannot find a way to include the requirements in an Embedded Web View Report. My MATLAB version is R2024a.
While it is easy to include the requirements when generating an standard webview form Simulink (see image below), it does not seem to be possible to do so with code in Embedded Web View Report generation.
The following code belongs to the class that i am using to generate this report (it is worth mentioning that there are no issues here, the report is correctly generated):
function rpt = classReportGeneratorWebview(reportName,modelName)
rpt@slreportgen.webview.EmbeddedWebViewDocument(…
reportName,modelName);
% Suppress Link Warning Messages for Embedded Web View Reports:
rpt.ValidateLinksAndAnchors = false;
% Specify Export Options for Embedded Web View Reports:
rpt.ExportOptions.SearchScope = ‘All’;
rpt.ExportOptions.IncludeReferencedModels = true;
rpt.ExportOptions.IncludeMaskedSubsystems = true;
end
As can be seen, the ExportOptions has properties that allow including multiple aspects. However, in the documentation (https://es.mathworks.com/help/rptgenext/ug/slreportgen.webview.exportoptions-class.html), there is no property related to including the requirements.
Therefore, when the report is generated, the button that allows access to the requirements view is obviously missing.
I would like to know if there is a way to include requirements in an Embedded Web View Report, inside the webview. Help would be much appreciated. report, webview, simulink, embedded webview report MATLAB Answers — New Questions
how to resolve “At least one value is out of range for rectangle or position” error?
Description: I have my own custom script for creating harness and in that While creating test harness i am facing this error on "create.m" default script at this line. i am using matlab 2018b version
>> Simulink.harness.create(harnessOwner, varargin{:});
and when i am trying to go inside this it is telling it is .p script so unable to debug it. so, after run the script it is giving me this error "At least one value is out of range for rectangle or position. All x values must be within -32786..32767 range, all y values must be within -32786..32767 range"Description: I have my own custom script for creating harness and in that While creating test harness i am facing this error on "create.m" default script at this line. i am using matlab 2018b version
>> Simulink.harness.create(harnessOwner, varargin{:});
and when i am trying to go inside this it is telling it is .p script so unable to debug it. so, after run the script it is giving me this error "At least one value is out of range for rectangle or position. All x values must be within -32786..32767 range, all y values must be within -32786..32767 range" Description: I have my own custom script for creating harness and in that While creating test harness i am facing this error on "create.m" default script at this line. i am using matlab 2018b version
>> Simulink.harness.create(harnessOwner, varargin{:});
and when i am trying to go inside this it is telling it is .p script so unable to debug it. so, after run the script it is giving me this error "At least one value is out of range for rectangle or position. All x values must be within -32786..32767 range, all y values must be within -32786..32767 range" out of range, -32786, matlab, simulink, harness, matlab function, create.m, urgent, matlab coder MATLAB Answers — New Questions
the mechanism of different syntax for realizing the same effect
hi, i wanted to ask is there some logics for remembering the syntax in Matlab, because sometimes i found the syntax have different logics, which confused myself. For example, < box on/off > is a simplified syntax in controlling whether the axis box is on. There are two syntax with different logics on controlling box. One is < box(ax,"off") >, and the other one is < set(ax,"box","off") > . PS. The former is probably the full form of < box off > ?? These two forms have different starting point within it. But when it comes to setting xlabel, it seems we could only use < xlabel("Time") >, and < set(ax,"XLabel","Time") > doesnot work. Why is this so as both box and XLabel are the properties of Axis. The funny thing is that < ax.XLabel.String = "Time" > is also ok. Can someone help explain? Thanks.hi, i wanted to ask is there some logics for remembering the syntax in Matlab, because sometimes i found the syntax have different logics, which confused myself. For example, < box on/off > is a simplified syntax in controlling whether the axis box is on. There are two syntax with different logics on controlling box. One is < box(ax,"off") >, and the other one is < set(ax,"box","off") > . PS. The former is probably the full form of < box off > ?? These two forms have different starting point within it. But when it comes to setting xlabel, it seems we could only use < xlabel("Time") >, and < set(ax,"XLabel","Time") > doesnot work. Why is this so as both box and XLabel are the properties of Axis. The funny thing is that < ax.XLabel.String = "Time" > is also ok. Can someone help explain? Thanks. hi, i wanted to ask is there some logics for remembering the syntax in Matlab, because sometimes i found the syntax have different logics, which confused myself. For example, < box on/off > is a simplified syntax in controlling whether the axis box is on. There are two syntax with different logics on controlling box. One is < box(ax,"off") >, and the other one is < set(ax,"box","off") > . PS. The former is probably the full form of < box off > ?? These two forms have different starting point within it. But when it comes to setting xlabel, it seems we could only use < xlabel("Time") >, and < set(ax,"XLabel","Time") > doesnot work. Why is this so as both box and XLabel are the properties of Axis. The funny thing is that < ax.XLabel.String = "Time" > is also ok. Can someone help explain? Thanks. box, axis, label MATLAB Answers — New Questions
WSL, ROS Humble – Simulink
Hello,
I am using ROS Humbe on WSL2 with Ubuntu 22.04 and I was wondering if I should install MATLAB into my Ubuntu System ? Or MATLAB on my Windows can still communicate with ROS ? Has any one ever tried using it ?Hello,
I am using ROS Humbe on WSL2 with Ubuntu 22.04 and I was wondering if I should install MATLAB into my Ubuntu System ? Or MATLAB on my Windows can still communicate with ROS ? Has any one ever tried using it ? Hello,
I am using ROS Humbe on WSL2 with Ubuntu 22.04 and I was wondering if I should install MATLAB into my Ubuntu System ? Or MATLAB on my Windows can still communicate with ROS ? Has any one ever tried using it ? simulink, matlab MATLAB Answers — New Questions
Scrollable Plot in real time from Arduino to Matlab
Hi,
I meet a problem when plotting data from Arduino to Matlab, where the x axis is increasing continously and cause the compression of plot. I want to let the x axis auto-scroll, something like axis(t,t+dx,y1,y2). I’ve tried two ways plotting the data, shown below. Is there any other methods to make the x axis auto-scrolling? Thank you in advance!
Method 1
%Method 1
clear all
a = arduino(‘COM5′,’ProMini328_5v’);
%interv = 10;
passo = 1;
t=1;
x=0;
%while(t<interv)
while(t)
b=a.readVoltage(‘A3’);
x=[x,b];
plot(x);
%axis([0,interv,0,5]);
ylim(‘auto’);
grid
t=t+passo;
drawnow;
end
Method 2
clear all
clc
%User Defined Properties
a = arduino(‘COM5′,’ProMini328_5v’); % define the Arduino Communication port
plotTitle = ‘Arduino Data Log’; % plot title
xLabel = ‘Elapsed Time (s)’; % x-axis label
yLabel = ‘Voltage’; % y-axis label
legend1 = ‘Optical Channel 1’;
legend2 = ‘Optical Channel 2’;
yMax = 40 %y Maximum Value
yMin = 0 %y minimum Value
plotGrid = ‘on’; % ‘off’ to turn off grid
min = 0; % set y-min
max = 40; % set y-max
delay = .01; % make sure sample faster than resolution
%Define Function Variables
time = 0;
data = 0;
data1 = 0;
data2 = 0;
count = 0;
%Set up Plot
%plotGraph = plot(time,data,’-r’ ) % every AnalogRead needs to be on its own Plotgraph
plotGraph1 = plot(time,data1,’-b’)
hold on %hold on makes sure all of the channels are plotted
plotGraph2 = plot(time, data2,’-g’ )
title(plotTitle,’FontSize’,15);
xlabel(xLabel,’FontSize’,15);
ylabel(yLabel,’FontSize’,15);
legend(legend1,legend2);
axis([yMin yMax min max]);
grid(plotGrid);
tic
while ishandle(plotGraph1) %Loop when Plot is Active will run until plot is closed
%dat = a.analogRead(0)* 0.48875855327; %Data from the arduino
%dat1 = a.analogRead(2)* 0.48875855327;
%dat2 = a.analogRead(3)* 0.48875855327;
dat1 = readVoltage(a,’A2′);
dat2 = readVoltage(a,’A3′);
count = count + 1;
time(count) = toc;
%data(count) = dat(1);
data1(count) = dat1(1)
data2(count) = dat2(1)
%This is the magic code
%Using plot will slow down the sampling time.. At times to over 20
%seconds per sample!
%set(plotGraph,’XData’,time,’YData’,data);
set(plotGraph1,’XData’,time,’YData’,data1);
set(plotGraph2,’XData’,time,’YData’,data2);
%x = linspace(0,100,10000);
xlim([0 30]);
%xticks(‘auto’);
ylim(‘auto’);
%axis([time(count) time(count)+10 min max]);
%axis([0 time(count) 1 5]);
%xlim([max(0,time(count)-0.1) max(10,time(count)-0.1)]);
%ylim(min,max);
%Update the graph
pause(delay);
end
delete(a);Hi,
I meet a problem when plotting data from Arduino to Matlab, where the x axis is increasing continously and cause the compression of plot. I want to let the x axis auto-scroll, something like axis(t,t+dx,y1,y2). I’ve tried two ways plotting the data, shown below. Is there any other methods to make the x axis auto-scrolling? Thank you in advance!
Method 1
%Method 1
clear all
a = arduino(‘COM5′,’ProMini328_5v’);
%interv = 10;
passo = 1;
t=1;
x=0;
%while(t<interv)
while(t)
b=a.readVoltage(‘A3’);
x=[x,b];
plot(x);
%axis([0,interv,0,5]);
ylim(‘auto’);
grid
t=t+passo;
drawnow;
end
Method 2
clear all
clc
%User Defined Properties
a = arduino(‘COM5′,’ProMini328_5v’); % define the Arduino Communication port
plotTitle = ‘Arduino Data Log’; % plot title
xLabel = ‘Elapsed Time (s)’; % x-axis label
yLabel = ‘Voltage’; % y-axis label
legend1 = ‘Optical Channel 1’;
legend2 = ‘Optical Channel 2’;
yMax = 40 %y Maximum Value
yMin = 0 %y minimum Value
plotGrid = ‘on’; % ‘off’ to turn off grid
min = 0; % set y-min
max = 40; % set y-max
delay = .01; % make sure sample faster than resolution
%Define Function Variables
time = 0;
data = 0;
data1 = 0;
data2 = 0;
count = 0;
%Set up Plot
%plotGraph = plot(time,data,’-r’ ) % every AnalogRead needs to be on its own Plotgraph
plotGraph1 = plot(time,data1,’-b’)
hold on %hold on makes sure all of the channels are plotted
plotGraph2 = plot(time, data2,’-g’ )
title(plotTitle,’FontSize’,15);
xlabel(xLabel,’FontSize’,15);
ylabel(yLabel,’FontSize’,15);
legend(legend1,legend2);
axis([yMin yMax min max]);
grid(plotGrid);
tic
while ishandle(plotGraph1) %Loop when Plot is Active will run until plot is closed
%dat = a.analogRead(0)* 0.48875855327; %Data from the arduino
%dat1 = a.analogRead(2)* 0.48875855327;
%dat2 = a.analogRead(3)* 0.48875855327;
dat1 = readVoltage(a,’A2′);
dat2 = readVoltage(a,’A3′);
count = count + 1;
time(count) = toc;
%data(count) = dat(1);
data1(count) = dat1(1)
data2(count) = dat2(1)
%This is the magic code
%Using plot will slow down the sampling time.. At times to over 20
%seconds per sample!
%set(plotGraph,’XData’,time,’YData’,data);
set(plotGraph1,’XData’,time,’YData’,data1);
set(plotGraph2,’XData’,time,’YData’,data2);
%x = linspace(0,100,10000);
xlim([0 30]);
%xticks(‘auto’);
ylim(‘auto’);
%axis([time(count) time(count)+10 min max]);
%axis([0 time(count) 1 5]);
%xlim([max(0,time(count)-0.1) max(10,time(count)-0.1)]);
%ylim(min,max);
%Update the graph
pause(delay);
end
delete(a); Hi,
I meet a problem when plotting data from Arduino to Matlab, where the x axis is increasing continously and cause the compression of plot. I want to let the x axis auto-scroll, something like axis(t,t+dx,y1,y2). I’ve tried two ways plotting the data, shown below. Is there any other methods to make the x axis auto-scrolling? Thank you in advance!
Method 1
%Method 1
clear all
a = arduino(‘COM5′,’ProMini328_5v’);
%interv = 10;
passo = 1;
t=1;
x=0;
%while(t<interv)
while(t)
b=a.readVoltage(‘A3’);
x=[x,b];
plot(x);
%axis([0,interv,0,5]);
ylim(‘auto’);
grid
t=t+passo;
drawnow;
end
Method 2
clear all
clc
%User Defined Properties
a = arduino(‘COM5′,’ProMini328_5v’); % define the Arduino Communication port
plotTitle = ‘Arduino Data Log’; % plot title
xLabel = ‘Elapsed Time (s)’; % x-axis label
yLabel = ‘Voltage’; % y-axis label
legend1 = ‘Optical Channel 1’;
legend2 = ‘Optical Channel 2’;
yMax = 40 %y Maximum Value
yMin = 0 %y minimum Value
plotGrid = ‘on’; % ‘off’ to turn off grid
min = 0; % set y-min
max = 40; % set y-max
delay = .01; % make sure sample faster than resolution
%Define Function Variables
time = 0;
data = 0;
data1 = 0;
data2 = 0;
count = 0;
%Set up Plot
%plotGraph = plot(time,data,’-r’ ) % every AnalogRead needs to be on its own Plotgraph
plotGraph1 = plot(time,data1,’-b’)
hold on %hold on makes sure all of the channels are plotted
plotGraph2 = plot(time, data2,’-g’ )
title(plotTitle,’FontSize’,15);
xlabel(xLabel,’FontSize’,15);
ylabel(yLabel,’FontSize’,15);
legend(legend1,legend2);
axis([yMin yMax min max]);
grid(plotGrid);
tic
while ishandle(plotGraph1) %Loop when Plot is Active will run until plot is closed
%dat = a.analogRead(0)* 0.48875855327; %Data from the arduino
%dat1 = a.analogRead(2)* 0.48875855327;
%dat2 = a.analogRead(3)* 0.48875855327;
dat1 = readVoltage(a,’A2′);
dat2 = readVoltage(a,’A3′);
count = count + 1;
time(count) = toc;
%data(count) = dat(1);
data1(count) = dat1(1)
data2(count) = dat2(1)
%This is the magic code
%Using plot will slow down the sampling time.. At times to over 20
%seconds per sample!
%set(plotGraph,’XData’,time,’YData’,data);
set(plotGraph1,’XData’,time,’YData’,data1);
set(plotGraph2,’XData’,time,’YData’,data2);
%x = linspace(0,100,10000);
xlim([0 30]);
%xticks(‘auto’);
ylim(‘auto’);
%axis([time(count) time(count)+10 min max]);
%axis([0 time(count) 1 5]);
%xlim([max(0,time(count)-0.1) max(10,time(count)-0.1)]);
%ylim(min,max);
%Update the graph
pause(delay);
end
delete(a); arduino, autoscroll scroll plot live plot MATLAB Answers — New Questions
help with bvp4c error
Hello! I am trying to solve a system of four coupled differential equation with two-point boundary conditions. I am getting errors and i am new to this, so i dont understand. Please help me fix it.
function proca_star
clear;
clc;
format long;
infinity = 10;
w=0.817;
x_init=1e-5:0.01:infinity;
global phi_c
for phi_c=[0.394 0.394 0 0]
%solinit = bvpinit(linspace(1e-5,infinity,1000),[1 1 phi_c 0],omega);
solinit = bvpinit(x_init,[1 1 phi_c 0],w);
options = bvpset(‘stats’,’on’,’RelTol’,1e-6);
%condition=true;
%while condition
sol = bvp4c(@bsode,@bsbc,solinit,options);
%condition = sol.stats.maxerr >= 1e-5;
%end
r_data = sol.x;
f = sol.y;
% Plotting the results
figure(1)
plot(r_data, f(1,:));
axis([0 infinity 0 1.5]);
title(‘sigma vs r’)
xlabel(‘r’)
ylabel(‘sigma’)
figure(2)
plot(r_data, f(2,:));
axis([0 infinity -0.5 1]);
title(‘f vs r’)
xlabel(‘r’)
ylabel(‘f’)
figure(3)
plot(r_data, f(3,:));
axis([0 infinity 0 1]);
title(‘m vs r’)
xlabel(‘r’)
ylabel(‘m’)
figure(4)
plot(r_data, f(4,:));
axis([0 infinity -0.5 1.5]);
title(‘g vs r’)
xlabel(‘r’)
ylabel(‘g’)
end
end
% ————————————————————————–
function dfdr = bsode(r, y)
w = 0.817;
N = 1 – 2 * y(3) / r;
dfdr = [4 * pi * r * 0.745 * (y(4)^2 + y(2)^2 / (N^2 * y(1)^2))
w * y(4) – 0.745 * y(1)^2 * N * y(4) / w
4 * pi * r^2 * (((0.745 * y(1)^2 * N^2 * y(4)^2)^2) / (2 * y(1)^2 * w^2) + 0.5 * 0.745 * (y(4)^2 * N + y(2)^2 / (N * y(1)^2)))
r^2 * y(2) * w / (y(1)^2 * N^2) – 2 * y(4)];
end
% ————————————————————————–
function res = bsbc(ya, yb)
global phi_c
res = [ya(1) – 0.394
ya(2) – 0.394
ya(3) – 0
ya(4) – 0
yb(1) – 1
yb(2) – 0
yb(3) – 0.745
yb(4) – 0];
end
Here is the error shown:
Error using proca_star>bsode
Too many input arguments.
Error in bvparguments (line 96)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in proca_star (line 22)
sol = bvp4c(@bsode,@bsbc,solinit,options);Hello! I am trying to solve a system of four coupled differential equation with two-point boundary conditions. I am getting errors and i am new to this, so i dont understand. Please help me fix it.
function proca_star
clear;
clc;
format long;
infinity = 10;
w=0.817;
x_init=1e-5:0.01:infinity;
global phi_c
for phi_c=[0.394 0.394 0 0]
%solinit = bvpinit(linspace(1e-5,infinity,1000),[1 1 phi_c 0],omega);
solinit = bvpinit(x_init,[1 1 phi_c 0],w);
options = bvpset(‘stats’,’on’,’RelTol’,1e-6);
%condition=true;
%while condition
sol = bvp4c(@bsode,@bsbc,solinit,options);
%condition = sol.stats.maxerr >= 1e-5;
%end
r_data = sol.x;
f = sol.y;
% Plotting the results
figure(1)
plot(r_data, f(1,:));
axis([0 infinity 0 1.5]);
title(‘sigma vs r’)
xlabel(‘r’)
ylabel(‘sigma’)
figure(2)
plot(r_data, f(2,:));
axis([0 infinity -0.5 1]);
title(‘f vs r’)
xlabel(‘r’)
ylabel(‘f’)
figure(3)
plot(r_data, f(3,:));
axis([0 infinity 0 1]);
title(‘m vs r’)
xlabel(‘r’)
ylabel(‘m’)
figure(4)
plot(r_data, f(4,:));
axis([0 infinity -0.5 1.5]);
title(‘g vs r’)
xlabel(‘r’)
ylabel(‘g’)
end
end
% ————————————————————————–
function dfdr = bsode(r, y)
w = 0.817;
N = 1 – 2 * y(3) / r;
dfdr = [4 * pi * r * 0.745 * (y(4)^2 + y(2)^2 / (N^2 * y(1)^2))
w * y(4) – 0.745 * y(1)^2 * N * y(4) / w
4 * pi * r^2 * (((0.745 * y(1)^2 * N^2 * y(4)^2)^2) / (2 * y(1)^2 * w^2) + 0.5 * 0.745 * (y(4)^2 * N + y(2)^2 / (N * y(1)^2)))
r^2 * y(2) * w / (y(1)^2 * N^2) – 2 * y(4)];
end
% ————————————————————————–
function res = bsbc(ya, yb)
global phi_c
res = [ya(1) – 0.394
ya(2) – 0.394
ya(3) – 0
ya(4) – 0
yb(1) – 1
yb(2) – 0
yb(3) – 0.745
yb(4) – 0];
end
Here is the error shown:
Error using proca_star>bsode
Too many input arguments.
Error in bvparguments (line 96)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in proca_star (line 22)
sol = bvp4c(@bsode,@bsbc,solinit,options); Hello! I am trying to solve a system of four coupled differential equation with two-point boundary conditions. I am getting errors and i am new to this, so i dont understand. Please help me fix it.
function proca_star
clear;
clc;
format long;
infinity = 10;
w=0.817;
x_init=1e-5:0.01:infinity;
global phi_c
for phi_c=[0.394 0.394 0 0]
%solinit = bvpinit(linspace(1e-5,infinity,1000),[1 1 phi_c 0],omega);
solinit = bvpinit(x_init,[1 1 phi_c 0],w);
options = bvpset(‘stats’,’on’,’RelTol’,1e-6);
%condition=true;
%while condition
sol = bvp4c(@bsode,@bsbc,solinit,options);
%condition = sol.stats.maxerr >= 1e-5;
%end
r_data = sol.x;
f = sol.y;
% Plotting the results
figure(1)
plot(r_data, f(1,:));
axis([0 infinity 0 1.5]);
title(‘sigma vs r’)
xlabel(‘r’)
ylabel(‘sigma’)
figure(2)
plot(r_data, f(2,:));
axis([0 infinity -0.5 1]);
title(‘f vs r’)
xlabel(‘r’)
ylabel(‘f’)
figure(3)
plot(r_data, f(3,:));
axis([0 infinity 0 1]);
title(‘m vs r’)
xlabel(‘r’)
ylabel(‘m’)
figure(4)
plot(r_data, f(4,:));
axis([0 infinity -0.5 1.5]);
title(‘g vs r’)
xlabel(‘r’)
ylabel(‘g’)
end
end
% ————————————————————————–
function dfdr = bsode(r, y)
w = 0.817;
N = 1 – 2 * y(3) / r;
dfdr = [4 * pi * r * 0.745 * (y(4)^2 + y(2)^2 / (N^2 * y(1)^2))
w * y(4) – 0.745 * y(1)^2 * N * y(4) / w
4 * pi * r^2 * (((0.745 * y(1)^2 * N^2 * y(4)^2)^2) / (2 * y(1)^2 * w^2) + 0.5 * 0.745 * (y(4)^2 * N + y(2)^2 / (N * y(1)^2)))
r^2 * y(2) * w / (y(1)^2 * N^2) – 2 * y(4)];
end
% ————————————————————————–
function res = bsbc(ya, yb)
global phi_c
res = [ya(1) – 0.394
ya(2) – 0.394
ya(3) – 0
ya(4) – 0
yb(1) – 1
yb(2) – 0
yb(3) – 0.745
yb(4) – 0];
end
Here is the error shown:
Error using proca_star>bsode
Too many input arguments.
Error in bvparguments (line 96)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in proca_star (line 22)
sol = bvp4c(@bsode,@bsbc,solinit,options); bvp4c, boundary value problem, coupled odes, error MATLAB Answers — New Questions
Time series – How to use a loop
Hi, I’m working on a timeseries as you can see. I can canculate my results from 0-2 years and after that from 0-3 years until i reach the 20 years. Do you how to aytomatic this procces only by using a loop ?
The step to go from 0 year to 2 is by default 1 day.
Also i don’t know how i can put my data in a loop so everytime i’m gonna use a loop fow an extra year there will be raised by 365.25 daysHi, I’m working on a timeseries as you can see. I can canculate my results from 0-2 years and after that from 0-3 years until i reach the 20 years. Do you how to aytomatic this procces only by using a loop ?
The step to go from 0 year to 2 is by default 1 day.
Also i don’t know how i can put my data in a loop so everytime i’m gonna use a loop fow an extra year there will be raised by 365.25 days Hi, I’m working on a timeseries as you can see. I can canculate my results from 0-2 years and after that from 0-3 years until i reach the 20 years. Do you how to aytomatic this procces only by using a loop ?
The step to go from 0 year to 2 is by default 1 day.
Also i don’t know how i can put my data in a loop so everytime i’m gonna use a loop fow an extra year there will be raised by 365.25 days loop, time series MATLAB Answers — New Questions
How to use tcpclient instead of tcpip with icdevice
I am using instrfind and tcpip to create interface object. I am pasing this interface object in icdevice to create object of my matlab intrument device driver. As, instrfind and tcpip will be removed in future release, how can I modify my code to use my instrument device driver? If I replace tcpip with tcpclient then I cannot use icdevice to create object of my intrument device driver. Refer below code which I am using.
% Create a TCPIP object.
interfaceObj = instrfind(‘Type’, ‘tcpip’, ‘RemoteHost’, ‘127.0.0.1’, ‘RemotePort’, 1234, ‘Tag’, ”);
% Create the TCPIP object if it does not exist
% otherwise use the object that was found.
if isempty(interfaceObj)
interfaceObj = tcpip(‘127.0.0.1’, 1234);
else
fclose(interfaceObj);
interfaceObj = interfaceObj(1);
end
% Create a device object.
deviceObj = icdevice(‘my_driver.mdd’, interfaceObj);
% Connect device object to hardware.
connect(deviceObj);I am using instrfind and tcpip to create interface object. I am pasing this interface object in icdevice to create object of my matlab intrument device driver. As, instrfind and tcpip will be removed in future release, how can I modify my code to use my instrument device driver? If I replace tcpip with tcpclient then I cannot use icdevice to create object of my intrument device driver. Refer below code which I am using.
% Create a TCPIP object.
interfaceObj = instrfind(‘Type’, ‘tcpip’, ‘RemoteHost’, ‘127.0.0.1’, ‘RemotePort’, 1234, ‘Tag’, ”);
% Create the TCPIP object if it does not exist
% otherwise use the object that was found.
if isempty(interfaceObj)
interfaceObj = tcpip(‘127.0.0.1’, 1234);
else
fclose(interfaceObj);
interfaceObj = interfaceObj(1);
end
% Create a device object.
deviceObj = icdevice(‘my_driver.mdd’, interfaceObj);
% Connect device object to hardware.
connect(deviceObj); I am using instrfind and tcpip to create interface object. I am pasing this interface object in icdevice to create object of my matlab intrument device driver. As, instrfind and tcpip will be removed in future release, how can I modify my code to use my instrument device driver? If I replace tcpip with tcpclient then I cannot use icdevice to create object of my intrument device driver. Refer below code which I am using.
% Create a TCPIP object.
interfaceObj = instrfind(‘Type’, ‘tcpip’, ‘RemoteHost’, ‘127.0.0.1’, ‘RemotePort’, 1234, ‘Tag’, ”);
% Create the TCPIP object if it does not exist
% otherwise use the object that was found.
if isempty(interfaceObj)
interfaceObj = tcpip(‘127.0.0.1’, 1234);
else
fclose(interfaceObj);
interfaceObj = interfaceObj(1);
end
% Create a device object.
deviceObj = icdevice(‘my_driver.mdd’, interfaceObj);
% Connect device object to hardware.
connect(deviceObj); instrfind, tcpip, removed in future release, instrument device driver MATLAB Answers — New Questions
Matlab code for Sorting diagonal elements of matrix and index of sorted elements is filled into new matrix as shown below?
This first matrix table1 contains normalized values for 5 names.I need to perform some operations on this matrix and I have to obtain second matrix as shown in table2.
Diagonal elements of table2 should obtained by giving rank(ordinal value) to each value.That means highest element is given 5th rank and next highest is given 4th 3rd and so on.
OPERATION:For diagonal elements
B(1,1)=5(first largest element)
B(2,2)=1(5th largest element)
B(3,3)=4(4th largest element)
B(4,4)=2(2nd largest element)
B(5,5)=3(3rd largest element)
Table1:
BASAVARAJ MANOJ NATESH VIJAY GOWDA
BASAVARAJ 1.0000 0.2727 0.3182 0.0455 0.2727
MANOJ 0.2727 0.2727 0 0 0
NATESH 0.3182 0 0.4545 0.1818 0
VIJAY 0.0455 0 0.1818 0.2727 0.0909
GOWDA 0.2727 0 0 0.0909 0.3636
Table2:
BASAVARAJ MANOJ NATESH VIJAY GOWDA
BASAVARAJ 5 0 0 0 0
MANOJ 0 1 0 0 0
NATESH 0 0 4 0 0
VIJAY 0 0 0 2 0
GOWDA 0 0 0 0 3This first matrix table1 contains normalized values for 5 names.I need to perform some operations on this matrix and I have to obtain second matrix as shown in table2.
Diagonal elements of table2 should obtained by giving rank(ordinal value) to each value.That means highest element is given 5th rank and next highest is given 4th 3rd and so on.
OPERATION:For diagonal elements
B(1,1)=5(first largest element)
B(2,2)=1(5th largest element)
B(3,3)=4(4th largest element)
B(4,4)=2(2nd largest element)
B(5,5)=3(3rd largest element)
Table1:
BASAVARAJ MANOJ NATESH VIJAY GOWDA
BASAVARAJ 1.0000 0.2727 0.3182 0.0455 0.2727
MANOJ 0.2727 0.2727 0 0 0
NATESH 0.3182 0 0.4545 0.1818 0
VIJAY 0.0455 0 0.1818 0.2727 0.0909
GOWDA 0.2727 0 0 0.0909 0.3636
Table2:
BASAVARAJ MANOJ NATESH VIJAY GOWDA
BASAVARAJ 5 0 0 0 0
MANOJ 0 1 0 0 0
NATESH 0 0 4 0 0
VIJAY 0 0 0 2 0
GOWDA 0 0 0 0 3 This first matrix table1 contains normalized values for 5 names.I need to perform some operations on this matrix and I have to obtain second matrix as shown in table2.
Diagonal elements of table2 should obtained by giving rank(ordinal value) to each value.That means highest element is given 5th rank and next highest is given 4th 3rd and so on.
OPERATION:For diagonal elements
B(1,1)=5(first largest element)
B(2,2)=1(5th largest element)
B(3,3)=4(4th largest element)
B(4,4)=2(2nd largest element)
B(5,5)=3(3rd largest element)
Table1:
BASAVARAJ MANOJ NATESH VIJAY GOWDA
BASAVARAJ 1.0000 0.2727 0.3182 0.0455 0.2727
MANOJ 0.2727 0.2727 0 0 0
NATESH 0.3182 0 0.4545 0.1818 0
VIJAY 0.0455 0 0.1818 0.2727 0.0909
GOWDA 0.2727 0 0 0.0909 0.3636
Table2:
BASAVARAJ MANOJ NATESH VIJAY GOWDA
BASAVARAJ 5 0 0 0 0
MANOJ 0 1 0 0 0
NATESH 0 0 4 0 0
VIJAY 0 0 0 2 0
GOWDA 0 0 0 0 3 matlab, matrix manipulation, sort, for loop, index MATLAB Answers — New Questions
I can’t find my land or junction id
https://kr.mathworks.com/videos/getting-started-with-roadrunner-junction-creation-in-roadrunner-1586438843851.html
At 4:34 in the video, I can see something called junction id.
I followed the same steps in the video, but I don’t see any attributes on my end.
Similarly, in another video, I saw something called lane id, but I couldn’t see anything on my road.
I have purchased Roadrunner license, but do I need to make an additional payment to use junction id or lane id? Or is there another way?https://kr.mathworks.com/videos/getting-started-with-roadrunner-junction-creation-in-roadrunner-1586438843851.html
At 4:34 in the video, I can see something called junction id.
I followed the same steps in the video, but I don’t see any attributes on my end.
Similarly, in another video, I saw something called lane id, but I couldn’t see anything on my road.
I have purchased Roadrunner license, but do I need to make an additional payment to use junction id or lane id? Or is there another way? https://kr.mathworks.com/videos/getting-started-with-roadrunner-junction-creation-in-roadrunner-1586438843851.html
At 4:34 in the video, I can see something called junction id.
I followed the same steps in the video, but I don’t see any attributes on my end.
Similarly, in another video, I saw something called lane id, but I couldn’t see anything on my road.
I have purchased Roadrunner license, but do I need to make an additional payment to use junction id or lane id? Or is there another way? id, junction, lane, junction id, lane id MATLAB Answers — New Questions
MATLAB editor shows files have no contents (blank)
Hello,
When I try to open an m-file or script in the editor, it opens up blank. The file, however, is clearly not empty – I can open it with a generic text editor and the code appears fine. This also happens if I try to create a new script in the editor. The editor opens a new ‘untitled’ file, but I can not enter any text in the editor.
I am running R2022b on an Apple M1 Max macOS 13.1
thanksHello,
When I try to open an m-file or script in the editor, it opens up blank. The file, however, is clearly not empty – I can open it with a generic text editor and the code appears fine. This also happens if I try to create a new script in the editor. The editor opens a new ‘untitled’ file, but I can not enter any text in the editor.
I am running R2022b on an Apple M1 Max macOS 13.1
thanks Hello,
When I try to open an m-file or script in the editor, it opens up blank. The file, however, is clearly not empty – I can open it with a generic text editor and the code appears fine. This also happens if I try to create a new script in the editor. The editor opens a new ‘untitled’ file, but I can not enter any text in the editor.
I am running R2022b on an Apple M1 Max macOS 13.1
thanks editor MATLAB Answers — New Questions
Can you please help me? My CPU usage remains consistently low when using parallel processing.
I investigated multiple reasons and discovered that the command matlab –prefersoftwareopengl is causing high I/O usage. How can I resolve this I/O hogging issue?
T1=20001;
T2=29000;
% Start the parallel pool
parpool(‘Threads’, 64);
N=T2-T1+1; % 数据点数
dmix = zeros(nx-start1-end1,ny-start2-end2,N);
parfor k = 1:N
i = T1 + k – 1;
fileName = sprintf(‘./left.out/m%06d.ovf’, i-1);
fid = fopen(fileName, ‘r’);
datam = textscan(fid, ‘%f%f%f’, ‘headerlines’, 28, ‘collectoutput’, 1);
fclose(fid);
datam = datam{1};
mix111 = reshape(datam(:,2), [nx, ny, nz]); % select x component
mix111 = permute(mix111, [2 1 3]); % x-y transform
mix11 = mix111(start1+1:nx-end1, start2+1:ny-end2, 2) – mix111(start1+1:nx-end1, start2+1:ny-end2, 1);
mix1 = squeeze(mix11);
% Compute the difference and store in dmix
dmix(:,:,k) = mix1;
end
delete(gcp(‘nocreate’));I investigated multiple reasons and discovered that the command matlab –prefersoftwareopengl is causing high I/O usage. How can I resolve this I/O hogging issue?
T1=20001;
T2=29000;
% Start the parallel pool
parpool(‘Threads’, 64);
N=T2-T1+1; % 数据点数
dmix = zeros(nx-start1-end1,ny-start2-end2,N);
parfor k = 1:N
i = T1 + k – 1;
fileName = sprintf(‘./left.out/m%06d.ovf’, i-1);
fid = fopen(fileName, ‘r’);
datam = textscan(fid, ‘%f%f%f’, ‘headerlines’, 28, ‘collectoutput’, 1);
fclose(fid);
datam = datam{1};
mix111 = reshape(datam(:,2), [nx, ny, nz]); % select x component
mix111 = permute(mix111, [2 1 3]); % x-y transform
mix11 = mix111(start1+1:nx-end1, start2+1:ny-end2, 2) – mix111(start1+1:nx-end1, start2+1:ny-end2, 1);
mix1 = squeeze(mix11);
% Compute the difference and store in dmix
dmix(:,:,k) = mix1;
end
delete(gcp(‘nocreate’)); I investigated multiple reasons and discovered that the command matlab –prefersoftwareopengl is causing high I/O usage. How can I resolve this I/O hogging issue?
T1=20001;
T2=29000;
% Start the parallel pool
parpool(‘Threads’, 64);
N=T2-T1+1; % 数据点数
dmix = zeros(nx-start1-end1,ny-start2-end2,N);
parfor k = 1:N
i = T1 + k – 1;
fileName = sprintf(‘./left.out/m%06d.ovf’, i-1);
fid = fopen(fileName, ‘r’);
datam = textscan(fid, ‘%f%f%f’, ‘headerlines’, 28, ‘collectoutput’, 1);
fclose(fid);
datam = datam{1};
mix111 = reshape(datam(:,2), [nx, ny, nz]); % select x component
mix111 = permute(mix111, [2 1 3]); % x-y transform
mix11 = mix111(start1+1:nx-end1, start2+1:ny-end2, 2) – mix111(start1+1:nx-end1, start2+1:ny-end2, 1);
mix1 = squeeze(mix11);
% Compute the difference and store in dmix
dmix(:,:,k) = mix1;
end
delete(gcp(‘nocreate’)); parallel computing toolbox, parallel computing MATLAB Answers — New Questions
How to export all the Test sequences from Simulink Test Manager as an excel file.
I am reviewing some older models, and I wish to be able to extract all Test Sequences for all Simulink Test Manager Files into an office document.I am reviewing some older models, and I wish to be able to extract all Test Sequences for all Simulink Test Manager Files into an office document. I am reviewing some older models, and I wish to be able to extract all Test Sequences for all Simulink Test Manager Files into an office document. simulink, test manager, test sequence MATLAB Answers — New Questions
solving system of 4 coupled odes using shooting method and boundary conditions given
Hello! i am trying to solve a boundary value problem with four coupled first order odes, with four initial conditions at r=0 and four boundary conditions at r=10. my code is running but im not getting my desired output and it is not satisfying the conditions. Can someone help me finding where am i going wrong?
function proca_star_shooting_method
% Clear the workspace and command window
clear;
clc;
format long;
% Define constants and parameters
infinity = 10;
w = 0.817;
x_init = linspace(1e-5, infinity, 1000); % More efficient space vector
% Define initial conditions and boundary conditions
initial_conditions = [0.394, 0.394, 0, 0];
boundary_conditions = [1, 0, 0.745, 0];
% Shooting method with RK4 integration
options = optimset(‘TolX’, 1e-6, ‘Display’, ‘iter’);
phi_c_shoot = fminbnd(@(phi_c) shooting_error(phi_c, x_init, initial_conditions, boundary_conditions, w), 0, 1, options);
% Solve the BVP using the optimal phi_c obtained from the shooting method
[r_data, y_data] = solve_bvp(x_init, initial_conditions, phi_c_shoot, w);
% Plot the results
plot_results(r_data, y_data, infinity);
end
function error = shooting_error(phi_c, x_init, initial_conditions, boundary_conditions, w)
% Solve BVP with given phi_c and calculate the error at the boundary
[~, y_data] = solve_bvp(x_init, initial_conditions, phi_c, w);
yb = y_data(:, end);
error = norm(yb – boundary_conditions’);
end
function [r_data, y_data] = solve_bvp(x_init, initial_conditions, phi_c, w)
% Define the initial conditions for the solver
y0 = [initial_conditions(1), initial_conditions(2), initial_conditions(3), phi_c];
% Initialize the solution arrays
r_data = x_init;
y_data = zeros(4, length(x_init));
y_data(:, 1) = y0;
h = x_init(2) – x_init(1); % Step size
% RK4 integration loop
for i = 2:length(x_init)
y_data(:, i) = rk4_step(@(r, y) bsode(r, y, w), r_data(i-1), y_data(:, i-1), h);
end
end
function y_next = rk4_step(odefun, r, y, h)
% Perform one step of RK4 integration
k1 = h * odefun(r, y);
k2 = h * odefun(r + h/2, y + k1/2);
k3 = h * odefun(r + h/2, y + k2/2);
k4 = h * odefun(r + h, y + k3);
y_next = y + (k1 + 2*k2 + 2*k3 + k4) / 6;
end
function dfdr = bsode(r, y, w)
% Define the system of ODEs to be solved
N = 1 – 2 * y(3) / r;
dfdr = [
4 * pi * r * 0.745 * (y(4)^2 + y(2)^2 / (N^2 * y(1)^2));
w * y(4) – 0.745 * y(1)^2 * N * y(4) / w;
4 * pi * r^2 * (((0.745 * y(1)^2 * N^2 * y(4)^2)^2) / (2 * y(1)^2 * w^2) + 0.5 * 0.745 * (y(4)^2 * N + y(2)^2 / (N * y(1)^2)));
r^2 * y(2) * w / (y(1)^2 * N^2) – 2 * y(4)
];
end
function plot_results(r_data, y_data, infinity)
% Plot the results of the BVP solution
figure;
plot(r_data, y_data(1,:), r_data, y_data(2,:), r_data, y_data(3,:), r_data, y_data(4,:));
axis([0 infinity -0.5 1.2]);
title(‘Functions vs r’);
xlabel(‘r’);
ylabel(‘sigma’);
legend(‘y1’, ‘y2’, ‘y3’, ‘y4’);
grid on;
end
This is my desired plot. Please help me out!Hello! i am trying to solve a boundary value problem with four coupled first order odes, with four initial conditions at r=0 and four boundary conditions at r=10. my code is running but im not getting my desired output and it is not satisfying the conditions. Can someone help me finding where am i going wrong?
function proca_star_shooting_method
% Clear the workspace and command window
clear;
clc;
format long;
% Define constants and parameters
infinity = 10;
w = 0.817;
x_init = linspace(1e-5, infinity, 1000); % More efficient space vector
% Define initial conditions and boundary conditions
initial_conditions = [0.394, 0.394, 0, 0];
boundary_conditions = [1, 0, 0.745, 0];
% Shooting method with RK4 integration
options = optimset(‘TolX’, 1e-6, ‘Display’, ‘iter’);
phi_c_shoot = fminbnd(@(phi_c) shooting_error(phi_c, x_init, initial_conditions, boundary_conditions, w), 0, 1, options);
% Solve the BVP using the optimal phi_c obtained from the shooting method
[r_data, y_data] = solve_bvp(x_init, initial_conditions, phi_c_shoot, w);
% Plot the results
plot_results(r_data, y_data, infinity);
end
function error = shooting_error(phi_c, x_init, initial_conditions, boundary_conditions, w)
% Solve BVP with given phi_c and calculate the error at the boundary
[~, y_data] = solve_bvp(x_init, initial_conditions, phi_c, w);
yb = y_data(:, end);
error = norm(yb – boundary_conditions’);
end
function [r_data, y_data] = solve_bvp(x_init, initial_conditions, phi_c, w)
% Define the initial conditions for the solver
y0 = [initial_conditions(1), initial_conditions(2), initial_conditions(3), phi_c];
% Initialize the solution arrays
r_data = x_init;
y_data = zeros(4, length(x_init));
y_data(:, 1) = y0;
h = x_init(2) – x_init(1); % Step size
% RK4 integration loop
for i = 2:length(x_init)
y_data(:, i) = rk4_step(@(r, y) bsode(r, y, w), r_data(i-1), y_data(:, i-1), h);
end
end
function y_next = rk4_step(odefun, r, y, h)
% Perform one step of RK4 integration
k1 = h * odefun(r, y);
k2 = h * odefun(r + h/2, y + k1/2);
k3 = h * odefun(r + h/2, y + k2/2);
k4 = h * odefun(r + h, y + k3);
y_next = y + (k1 + 2*k2 + 2*k3 + k4) / 6;
end
function dfdr = bsode(r, y, w)
% Define the system of ODEs to be solved
N = 1 – 2 * y(3) / r;
dfdr = [
4 * pi * r * 0.745 * (y(4)^2 + y(2)^2 / (N^2 * y(1)^2));
w * y(4) – 0.745 * y(1)^2 * N * y(4) / w;
4 * pi * r^2 * (((0.745 * y(1)^2 * N^2 * y(4)^2)^2) / (2 * y(1)^2 * w^2) + 0.5 * 0.745 * (y(4)^2 * N + y(2)^2 / (N * y(1)^2)));
r^2 * y(2) * w / (y(1)^2 * N^2) – 2 * y(4)
];
end
function plot_results(r_data, y_data, infinity)
% Plot the results of the BVP solution
figure;
plot(r_data, y_data(1,:), r_data, y_data(2,:), r_data, y_data(3,:), r_data, y_data(4,:));
axis([0 infinity -0.5 1.2]);
title(‘Functions vs r’);
xlabel(‘r’);
ylabel(‘sigma’);
legend(‘y1’, ‘y2’, ‘y3’, ‘y4’);
grid on;
end
This is my desired plot. Please help me out! Hello! i am trying to solve a boundary value problem with four coupled first order odes, with four initial conditions at r=0 and four boundary conditions at r=10. my code is running but im not getting my desired output and it is not satisfying the conditions. Can someone help me finding where am i going wrong?
function proca_star_shooting_method
% Clear the workspace and command window
clear;
clc;
format long;
% Define constants and parameters
infinity = 10;
w = 0.817;
x_init = linspace(1e-5, infinity, 1000); % More efficient space vector
% Define initial conditions and boundary conditions
initial_conditions = [0.394, 0.394, 0, 0];
boundary_conditions = [1, 0, 0.745, 0];
% Shooting method with RK4 integration
options = optimset(‘TolX’, 1e-6, ‘Display’, ‘iter’);
phi_c_shoot = fminbnd(@(phi_c) shooting_error(phi_c, x_init, initial_conditions, boundary_conditions, w), 0, 1, options);
% Solve the BVP using the optimal phi_c obtained from the shooting method
[r_data, y_data] = solve_bvp(x_init, initial_conditions, phi_c_shoot, w);
% Plot the results
plot_results(r_data, y_data, infinity);
end
function error = shooting_error(phi_c, x_init, initial_conditions, boundary_conditions, w)
% Solve BVP with given phi_c and calculate the error at the boundary
[~, y_data] = solve_bvp(x_init, initial_conditions, phi_c, w);
yb = y_data(:, end);
error = norm(yb – boundary_conditions’);
end
function [r_data, y_data] = solve_bvp(x_init, initial_conditions, phi_c, w)
% Define the initial conditions for the solver
y0 = [initial_conditions(1), initial_conditions(2), initial_conditions(3), phi_c];
% Initialize the solution arrays
r_data = x_init;
y_data = zeros(4, length(x_init));
y_data(:, 1) = y0;
h = x_init(2) – x_init(1); % Step size
% RK4 integration loop
for i = 2:length(x_init)
y_data(:, i) = rk4_step(@(r, y) bsode(r, y, w), r_data(i-1), y_data(:, i-1), h);
end
end
function y_next = rk4_step(odefun, r, y, h)
% Perform one step of RK4 integration
k1 = h * odefun(r, y);
k2 = h * odefun(r + h/2, y + k1/2);
k3 = h * odefun(r + h/2, y + k2/2);
k4 = h * odefun(r + h, y + k3);
y_next = y + (k1 + 2*k2 + 2*k3 + k4) / 6;
end
function dfdr = bsode(r, y, w)
% Define the system of ODEs to be solved
N = 1 – 2 * y(3) / r;
dfdr = [
4 * pi * r * 0.745 * (y(4)^2 + y(2)^2 / (N^2 * y(1)^2));
w * y(4) – 0.745 * y(1)^2 * N * y(4) / w;
4 * pi * r^2 * (((0.745 * y(1)^2 * N^2 * y(4)^2)^2) / (2 * y(1)^2 * w^2) + 0.5 * 0.745 * (y(4)^2 * N + y(2)^2 / (N * y(1)^2)));
r^2 * y(2) * w / (y(1)^2 * N^2) – 2 * y(4)
];
end
function plot_results(r_data, y_data, infinity)
% Plot the results of the BVP solution
figure;
plot(r_data, y_data(1,:), r_data, y_data(2,:), r_data, y_data(3,:), r_data, y_data(4,:));
axis([0 infinity -0.5 1.2]);
title(‘Functions vs r’);
xlabel(‘r’);
ylabel(‘sigma’);
legend(‘y1’, ‘y2’, ‘y3’, ‘y4’);
grid on;
end
This is my desired plot. Please help me out! shooting method, bvp4c, rk4, plot, boundary value problem MATLAB Answers — New Questions
Brace indexing error using fitcensemble
I am getting strange errors trying to use fitcensemble, so I refered to the manual, and ran the simple following example, which I found on the fitcensemble help page:
load census1994
Mdl1 = fitcensemble(adultdata,’salary’)
these two simple lines of code should result in a classification ensemble but instead I get the following error:
Error using classreg.learning.internal.callBuiltinFitEnsemble
Error: File: callBuiltinFitEnsemble.m Line: 191 Column: 41
Brace indexing into the result of a function call is not supported. Assign the result of ‘curvature’ to a variable first, then brace index into it.
Error in classreg.learning.ensemble.Ensemble/fitBuiltinEnsemble (line 457)
classreg.learning.internal.callBuiltinFitEnsemble(this.Method,…
Error in classreg.learning.classif.ClassificationEnsemble (line 85)
this = fitBuiltinEnsemble(this,nlearn,dataSummary,classSummary);
Error in classreg.learning.FitTemplate/fit (line 292)
[varargout{1:nargout}] = this.MakeFitObject(X,Y,W,this.ModelParams,fitArgs{:});
Error in fitensemble (line 364)
obj = fit(temp,X,Y);
Error in fitcensemble (line 212)
obj = fitensemble(X, Y, Method, NumLearningCycles, Learners, …
So I feel like the problem is not my code, but instead I wonder if the problem is with some of the recent updates?
I am using version: ‘24.1.0.2628055 (R2024a) Update 4’
on a 64-bit Windows® platformI am getting strange errors trying to use fitcensemble, so I refered to the manual, and ran the simple following example, which I found on the fitcensemble help page:
load census1994
Mdl1 = fitcensemble(adultdata,’salary’)
these two simple lines of code should result in a classification ensemble but instead I get the following error:
Error using classreg.learning.internal.callBuiltinFitEnsemble
Error: File: callBuiltinFitEnsemble.m Line: 191 Column: 41
Brace indexing into the result of a function call is not supported. Assign the result of ‘curvature’ to a variable first, then brace index into it.
Error in classreg.learning.ensemble.Ensemble/fitBuiltinEnsemble (line 457)
classreg.learning.internal.callBuiltinFitEnsemble(this.Method,…
Error in classreg.learning.classif.ClassificationEnsemble (line 85)
this = fitBuiltinEnsemble(this,nlearn,dataSummary,classSummary);
Error in classreg.learning.FitTemplate/fit (line 292)
[varargout{1:nargout}] = this.MakeFitObject(X,Y,W,this.ModelParams,fitArgs{:});
Error in fitensemble (line 364)
obj = fit(temp,X,Y);
Error in fitcensemble (line 212)
obj = fitensemble(X, Y, Method, NumLearningCycles, Learners, …
So I feel like the problem is not my code, but instead I wonder if the problem is with some of the recent updates?
I am using version: ‘24.1.0.2628055 (R2024a) Update 4’
on a 64-bit Windows® platform I am getting strange errors trying to use fitcensemble, so I refered to the manual, and ran the simple following example, which I found on the fitcensemble help page:
load census1994
Mdl1 = fitcensemble(adultdata,’salary’)
these two simple lines of code should result in a classification ensemble but instead I get the following error:
Error using classreg.learning.internal.callBuiltinFitEnsemble
Error: File: callBuiltinFitEnsemble.m Line: 191 Column: 41
Brace indexing into the result of a function call is not supported. Assign the result of ‘curvature’ to a variable first, then brace index into it.
Error in classreg.learning.ensemble.Ensemble/fitBuiltinEnsemble (line 457)
classreg.learning.internal.callBuiltinFitEnsemble(this.Method,…
Error in classreg.learning.classif.ClassificationEnsemble (line 85)
this = fitBuiltinEnsemble(this,nlearn,dataSummary,classSummary);
Error in classreg.learning.FitTemplate/fit (line 292)
[varargout{1:nargout}] = this.MakeFitObject(X,Y,W,this.ModelParams,fitArgs{:});
Error in fitensemble (line 364)
obj = fit(temp,X,Y);
Error in fitcensemble (line 212)
obj = fitensemble(X, Y, Method, NumLearningCycles, Learners, …
So I feel like the problem is not my code, but instead I wonder if the problem is with some of the recent updates?
I am using version: ‘24.1.0.2628055 (R2024a) Update 4’
on a 64-bit Windows® platform fitcensemble, error, brace indexing MATLAB Answers — New Questions
Fail to start parpool on cluster
Hello, I’m submitting a batch job using SLURM:
sbatch shllscrpt96_16jul2024.sh false iter 1
shllscrpt96_16jul2024.sh itself looks like:
#!/bin/bash
#SBATCH -n 96
#SBATCH –mail-type="ALL"
#SBATCH –mem-per-cpu=8000M
module purge
module load matlab/2023b
matlab -nosplash -nodesktop -nodisplay -r "scriptfun_11jul2024($1,’$2′,$3); exit"
scriptfun_11jul2024(run_Spec, ms_Display, Category_MS) itself looks like:
function scriptfun_11jul2024(run_Spec,ms_Display,Category_MS)
n_cores = str2double(getenv(‘SLURM_NTASKS’));
pool = parpool(‘local’, n_cores);
"lots of statements (I’m happy to provide more details, but I’m 100% sure this is not the part causing the problem..)"
delete(pool)
end
The batch job "successfully" completes, but the output file shows that it failed:
Starting parallel pool (parpool) using the ‘local’ profile …
Preserving jobs with IDs: 13 14 15 16 because they contain crash dump files.
You can use ‘delete(myCluster.Jobs)’ to remove all jobs created with profile Processes. To create ‘myCluster’ use ‘myCluster = parcluster(‘Processes’)’.
Parallel pool using the ‘Processes’ profile is shutting down.
{�Error using parpool
Parallel pool failed to start with the following error. For more detailed
information, validate the profile ‘Processes’ in the Cluster Profile Manager.
Error in kimscriptfun_11jul2024 (line 13)
pool = parpool(‘local’, n_cores);
Caused by:
Error using
parallel.internal.pool.AbstractInteractiveClient>iThrowWithCause
Failed to initialize the interactive session.
Error using
parallel.internal.pool.AbstractInteractiveClient>iThrowIfBadParallelJobStatus
The interactive communicating job failed with no message.
}�
I’d appreciate any and all thoughts on what I might have done wrong. Thank you!Hello, I’m submitting a batch job using SLURM:
sbatch shllscrpt96_16jul2024.sh false iter 1
shllscrpt96_16jul2024.sh itself looks like:
#!/bin/bash
#SBATCH -n 96
#SBATCH –mail-type="ALL"
#SBATCH –mem-per-cpu=8000M
module purge
module load matlab/2023b
matlab -nosplash -nodesktop -nodisplay -r "scriptfun_11jul2024($1,’$2′,$3); exit"
scriptfun_11jul2024(run_Spec, ms_Display, Category_MS) itself looks like:
function scriptfun_11jul2024(run_Spec,ms_Display,Category_MS)
n_cores = str2double(getenv(‘SLURM_NTASKS’));
pool = parpool(‘local’, n_cores);
"lots of statements (I’m happy to provide more details, but I’m 100% sure this is not the part causing the problem..)"
delete(pool)
end
The batch job "successfully" completes, but the output file shows that it failed:
Starting parallel pool (parpool) using the ‘local’ profile …
Preserving jobs with IDs: 13 14 15 16 because they contain crash dump files.
You can use ‘delete(myCluster.Jobs)’ to remove all jobs created with profile Processes. To create ‘myCluster’ use ‘myCluster = parcluster(‘Processes’)’.
Parallel pool using the ‘Processes’ profile is shutting down.
{�Error using parpool
Parallel pool failed to start with the following error. For more detailed
information, validate the profile ‘Processes’ in the Cluster Profile Manager.
Error in kimscriptfun_11jul2024 (line 13)
pool = parpool(‘local’, n_cores);
Caused by:
Error using
parallel.internal.pool.AbstractInteractiveClient>iThrowWithCause
Failed to initialize the interactive session.
Error using
parallel.internal.pool.AbstractInteractiveClient>iThrowIfBadParallelJobStatus
The interactive communicating job failed with no message.
}�
I’d appreciate any and all thoughts on what I might have done wrong. Thank you! Hello, I’m submitting a batch job using SLURM:
sbatch shllscrpt96_16jul2024.sh false iter 1
shllscrpt96_16jul2024.sh itself looks like:
#!/bin/bash
#SBATCH -n 96
#SBATCH –mail-type="ALL"
#SBATCH –mem-per-cpu=8000M
module purge
module load matlab/2023b
matlab -nosplash -nodesktop -nodisplay -r "scriptfun_11jul2024($1,’$2′,$3); exit"
scriptfun_11jul2024(run_Spec, ms_Display, Category_MS) itself looks like:
function scriptfun_11jul2024(run_Spec,ms_Display,Category_MS)
n_cores = str2double(getenv(‘SLURM_NTASKS’));
pool = parpool(‘local’, n_cores);
"lots of statements (I’m happy to provide more details, but I’m 100% sure this is not the part causing the problem..)"
delete(pool)
end
The batch job "successfully" completes, but the output file shows that it failed:
Starting parallel pool (parpool) using the ‘local’ profile …
Preserving jobs with IDs: 13 14 15 16 because they contain crash dump files.
You can use ‘delete(myCluster.Jobs)’ to remove all jobs created with profile Processes. To create ‘myCluster’ use ‘myCluster = parcluster(‘Processes’)’.
Parallel pool using the ‘Processes’ profile is shutting down.
{�Error using parpool
Parallel pool failed to start with the following error. For more detailed
information, validate the profile ‘Processes’ in the Cluster Profile Manager.
Error in kimscriptfun_11jul2024 (line 13)
pool = parpool(‘local’, n_cores);
Caused by:
Error using
parallel.internal.pool.AbstractInteractiveClient>iThrowWithCause
Failed to initialize the interactive session.
Error using
parallel.internal.pool.AbstractInteractiveClient>iThrowIfBadParallelJobStatus
The interactive communicating job failed with no message.
}�
I’d appreciate any and all thoughts on what I might have done wrong. Thank you! parpool, cluster, batch-job MATLAB Answers — New Questions