Category: Matlab
Category Archives: Matlab
Problem training Gaussian process with ‘ardsquaredexponential’ kernel function using bayesopt
Dear community,
I have a problem training a Gaussian process using fitrgp. Can someone advise, why some datasets will produce errors when training with the command below. The training data set that is causing the error is in the attached mat-file.
gpr = fitrgp(X, y, …
‘KernelFunction’, ‘ardsquaredexponential’,…
‘PredictMethod’, ‘fic’,…
‘OptimizeHyperparameters’, {‘KernelScale’,’Sigma’},…
‘HyperparameterOptimizationOptions’,…
struct(‘MaxObjectiveEvaluations’,250,…
‘Optimizer’, ‘bayesopt’,…
‘Repartition’, false,…
‘UseParallel’, true,…
‘Kfold’ , 5),…
‘Verbose’, 1,…
‘OptimizerOptions’, statset(…
‘Display’, ‘final’,…
‘UseParallel’, true));
The error that is returned reads
For the ‘ARDSquaredExponential’ kernel with 2 predictors, ‘KernelParameters’ must be a 3-by-1 vector of positive numbers.
and did not help me find a solution. (I already tried normalizing, more data, etc., but it did not work)
Best regards and thank you,
RobertDear community,
I have a problem training a Gaussian process using fitrgp. Can someone advise, why some datasets will produce errors when training with the command below. The training data set that is causing the error is in the attached mat-file.
gpr = fitrgp(X, y, …
‘KernelFunction’, ‘ardsquaredexponential’,…
‘PredictMethod’, ‘fic’,…
‘OptimizeHyperparameters’, {‘KernelScale’,’Sigma’},…
‘HyperparameterOptimizationOptions’,…
struct(‘MaxObjectiveEvaluations’,250,…
‘Optimizer’, ‘bayesopt’,…
‘Repartition’, false,…
‘UseParallel’, true,…
‘Kfold’ , 5),…
‘Verbose’, 1,…
‘OptimizerOptions’, statset(…
‘Display’, ‘final’,…
‘UseParallel’, true));
The error that is returned reads
For the ‘ARDSquaredExponential’ kernel with 2 predictors, ‘KernelParameters’ must be a 3-by-1 vector of positive numbers.
and did not help me find a solution. (I already tried normalizing, more data, etc., but it did not work)
Best regards and thank you,
Robert Dear community,
I have a problem training a Gaussian process using fitrgp. Can someone advise, why some datasets will produce errors when training with the command below. The training data set that is causing the error is in the attached mat-file.
gpr = fitrgp(X, y, …
‘KernelFunction’, ‘ardsquaredexponential’,…
‘PredictMethod’, ‘fic’,…
‘OptimizeHyperparameters’, {‘KernelScale’,’Sigma’},…
‘HyperparameterOptimizationOptions’,…
struct(‘MaxObjectiveEvaluations’,250,…
‘Optimizer’, ‘bayesopt’,…
‘Repartition’, false,…
‘UseParallel’, true,…
‘Kfold’ , 5),…
‘Verbose’, 1,…
‘OptimizerOptions’, statset(…
‘Display’, ‘final’,…
‘UseParallel’, true));
The error that is returned reads
For the ‘ARDSquaredExponential’ kernel with 2 predictors, ‘KernelParameters’ must be a 3-by-1 vector of positive numbers.
and did not help me find a solution. (I already tried normalizing, more data, etc., but it did not work)
Best regards and thank you,
Robert fitrgp, ‘ardsquaredexponential’, regression MATLAB Answers — New Questions
How to create a mesh surface from given 3D coordinates?
Hi all,
I’ve decided to give MATLAB a try for my research project.
I’m trying to create a 3D mesh of given coordinates E, N and elevation.
I can plot all the points using plot3(x,y,z,’.’);
Using an XLSX or csv spreadsheet for the datsets I have removed all unnecessary data such as point name and code leaving only E,N and elevation in a 460×3 table.
And using the patch function it does something but not creating the surface as I would like it as a mesh.
I would also like to set some parameters when creating the mesh i.e don’t create surface between outside points where distance between those points is greater than say 20m.
Attached is a screenshot of where I am up to.
Kind regards,
Mitch.Hi all,
I’ve decided to give MATLAB a try for my research project.
I’m trying to create a 3D mesh of given coordinates E, N and elevation.
I can plot all the points using plot3(x,y,z,’.’);
Using an XLSX or csv spreadsheet for the datsets I have removed all unnecessary data such as point name and code leaving only E,N and elevation in a 460×3 table.
And using the patch function it does something but not creating the surface as I would like it as a mesh.
I would also like to set some parameters when creating the mesh i.e don’t create surface between outside points where distance between those points is greater than say 20m.
Attached is a screenshot of where I am up to.
Kind regards,
Mitch. Hi all,
I’ve decided to give MATLAB a try for my research project.
I’m trying to create a 3D mesh of given coordinates E, N and elevation.
I can plot all the points using plot3(x,y,z,’.’);
Using an XLSX or csv spreadsheet for the datsets I have removed all unnecessary data such as point name and code leaving only E,N and elevation in a 460×3 table.
And using the patch function it does something but not creating the surface as I would like it as a mesh.
I would also like to set some parameters when creating the mesh i.e don’t create surface between outside points where distance between those points is greater than say 20m.
Attached is a screenshot of where I am up to.
Kind regards,
Mitch. mesh, surface, 3d, plot MATLAB Answers — New Questions
Can we simulate Custom Simulink Library block ?
As per rule; we can not simulate the custom Simulink library block ;But when I am using integrating it with normal model I am able to simulate and capture the expected resultAs per rule; we can not simulate the custom Simulink library block ;But when I am using integrating it with normal model I am able to simulate and capture the expected result As per rule; we can not simulate the custom Simulink library block ;But when I am using integrating it with normal model I am able to simulate and capture the expected result simulink, library, matlab, simulation MATLAB Answers — New Questions
Extract area from elipsoidal/cirle trajectory.
Dear all, how are you?
I created the following code to simulate an anticlockwise rotating trajectory forced by an external velocity. Now, I want to calculate the area each time the trajectory makes a closed circle, as described in the attached image. I would appreciate any help in finding the best way to identify the areas inside the circles for each loop/circle in the trajectory. Thanks for your time!
clear all,close all;
Fs = 1/0.5;
duration_hours = 25 * 24;
t = 0:1/Fs:duration_hours;
period = 20;
phase = -pi/2;
num_periods = floor(duration_hours / period);
amplitudes = 0.1/2 + 0.1 * rand(1, num_periods); % Random amplitudes between 0.1 and 0.3
y = zeros(size(t));
for i = 1:num_periods
start_idx = (i-1) * period * Fs + 1;
end_idx = i * period * Fs;
uI(start_idx:end_idx) = amplitudes(i) * sin(2*pi*(t(start_idx:end_idx) – t(start_idx))/period);
end
amplitudes = 0.1/2 + 0.1 * rand(1, num_periods); % Random amplitudes between 0.1 and 0.3
for i = 1:num_periods
start_idx = (i-1) * period * Fs + 1;
end_idx = i * period * Fs;
vI(start_idx:end_idx) = amplitudes(i) * sin(2*pi*(t(start_idx:end_idx) – t(start_idx))/period);
end
uI = uI(10:end);
vI = vI(1:length(uI));
cv = complex(uI*100,vI*100);
dt=0.5/24;
dt=dt*3600*24;
cxI=cumsum(cv)*dt;
cxI=cxI/100/1000;
x = real(cxI + complex(cumsum(repmat(0.1,1191,1)),0)’ );
y = imag(cxI + complex(cumsum(repmat(0.1,1191,1)),0)’ );
clearvars -except x y;
plot(x,y),axis equal;Dear all, how are you?
I created the following code to simulate an anticlockwise rotating trajectory forced by an external velocity. Now, I want to calculate the area each time the trajectory makes a closed circle, as described in the attached image. I would appreciate any help in finding the best way to identify the areas inside the circles for each loop/circle in the trajectory. Thanks for your time!
clear all,close all;
Fs = 1/0.5;
duration_hours = 25 * 24;
t = 0:1/Fs:duration_hours;
period = 20;
phase = -pi/2;
num_periods = floor(duration_hours / period);
amplitudes = 0.1/2 + 0.1 * rand(1, num_periods); % Random amplitudes between 0.1 and 0.3
y = zeros(size(t));
for i = 1:num_periods
start_idx = (i-1) * period * Fs + 1;
end_idx = i * period * Fs;
uI(start_idx:end_idx) = amplitudes(i) * sin(2*pi*(t(start_idx:end_idx) – t(start_idx))/period);
end
amplitudes = 0.1/2 + 0.1 * rand(1, num_periods); % Random amplitudes between 0.1 and 0.3
for i = 1:num_periods
start_idx = (i-1) * period * Fs + 1;
end_idx = i * period * Fs;
vI(start_idx:end_idx) = amplitudes(i) * sin(2*pi*(t(start_idx:end_idx) – t(start_idx))/period);
end
uI = uI(10:end);
vI = vI(1:length(uI));
cv = complex(uI*100,vI*100);
dt=0.5/24;
dt=dt*3600*24;
cxI=cumsum(cv)*dt;
cxI=cxI/100/1000;
x = real(cxI + complex(cumsum(repmat(0.1,1191,1)),0)’ );
y = imag(cxI + complex(cumsum(repmat(0.1,1191,1)),0)’ );
clearvars -except x y;
plot(x,y),axis equal; Dear all, how are you?
I created the following code to simulate an anticlockwise rotating trajectory forced by an external velocity. Now, I want to calculate the area each time the trajectory makes a closed circle, as described in the attached image. I would appreciate any help in finding the best way to identify the areas inside the circles for each loop/circle in the trajectory. Thanks for your time!
clear all,close all;
Fs = 1/0.5;
duration_hours = 25 * 24;
t = 0:1/Fs:duration_hours;
period = 20;
phase = -pi/2;
num_periods = floor(duration_hours / period);
amplitudes = 0.1/2 + 0.1 * rand(1, num_periods); % Random amplitudes between 0.1 and 0.3
y = zeros(size(t));
for i = 1:num_periods
start_idx = (i-1) * period * Fs + 1;
end_idx = i * period * Fs;
uI(start_idx:end_idx) = amplitudes(i) * sin(2*pi*(t(start_idx:end_idx) – t(start_idx))/period);
end
amplitudes = 0.1/2 + 0.1 * rand(1, num_periods); % Random amplitudes between 0.1 and 0.3
for i = 1:num_periods
start_idx = (i-1) * period * Fs + 1;
end_idx = i * period * Fs;
vI(start_idx:end_idx) = amplitudes(i) * sin(2*pi*(t(start_idx:end_idx) – t(start_idx))/period);
end
uI = uI(10:end);
vI = vI(1:length(uI));
cv = complex(uI*100,vI*100);
dt=0.5/24;
dt=dt*3600*24;
cxI=cumsum(cv)*dt;
cxI=cxI/100/1000;
x = real(cxI + complex(cumsum(repmat(0.1,1191,1)),0)’ );
y = imag(cxI + complex(cumsum(repmat(0.1,1191,1)),0)’ );
clearvars -except x y;
plot(x,y),axis equal; matlab, time series MATLAB Answers — New Questions
How to install PV_LIB Toolbox for Matlab
The download for PV_LIB is at:
PV_LIB Toolbox – PV Performance Modeling Collaborative (PVPMC) (sandia.gov)
I’ve looked at the Add-on Explorer and toolbox installation code in Matlab help:
Get and Manage Add-Ons – MATLAB & Simulink – MathWorks United Kingdom
Install toolbox file – MATLAB matlab.addons.toolbox.installToolbox – MathWorks United Kingdom
The problem is I can’t see anything with a .mltbx extension in the PV_LIB download. I think I only need a small relevant code snippet. Please can you advise.The download for PV_LIB is at:
PV_LIB Toolbox – PV Performance Modeling Collaborative (PVPMC) (sandia.gov)
I’ve looked at the Add-on Explorer and toolbox installation code in Matlab help:
Get and Manage Add-Ons – MATLAB & Simulink – MathWorks United Kingdom
Install toolbox file – MATLAB matlab.addons.toolbox.installToolbox – MathWorks United Kingdom
The problem is I can’t see anything with a .mltbx extension in the PV_LIB download. I think I only need a small relevant code snippet. Please can you advise. The download for PV_LIB is at:
PV_LIB Toolbox – PV Performance Modeling Collaborative (PVPMC) (sandia.gov)
I’ve looked at the Add-on Explorer and toolbox installation code in Matlab help:
Get and Manage Add-Ons – MATLAB & Simulink – MathWorks United Kingdom
Install toolbox file – MATLAB matlab.addons.toolbox.installToolbox – MathWorks United Kingdom
The problem is I can’t see anything with a .mltbx extension in the PV_LIB download. I think I only need a small relevant code snippet. Please can you advise. toolbox, pv_lib, photovoltaic, solar MATLAB Answers — New Questions
How to use ray tracing tool for visible light
Hello all,
I am working on MATLAB ray tracing tool for visible light communication. But the "txsite" command takes maximum "Transmitter Frequency" of 2e11 and starting frequency of visible light is 4.62e14. Please provide a solution to this problem.Hello all,
I am working on MATLAB ray tracing tool for visible light communication. But the "txsite" command takes maximum "Transmitter Frequency" of 2e11 and starting frequency of visible light is 4.62e14. Please provide a solution to this problem. Hello all,
I am working on MATLAB ray tracing tool for visible light communication. But the "txsite" command takes maximum "Transmitter Frequency" of 2e11 and starting frequency of visible light is 4.62e14. Please provide a solution to this problem. visiblelight MATLAB Answers — New Questions
User defined function for curve fitting, but the defined function is complicated
Hi all,
I am working on this project whihc requires me to fit my experimental data using a complicated function (function is attached in the picture below). May I ask how can I create this fitting function using matlab codes?
Information about function:
function (2):
dependent: A_CC
independent: hbar*omega
parameters: A_1, E_b, E_g, Gamma
function (3):
dependent: A_EC
independent: hbar*omega
parameters: A_2, E_b, E_g, Gamma
Please note that any over lapping terms in both functions should have the same value. For instance, Gamma exist in both (2) and (3), and hence they need to have the same value.
thank you!Hi all,
I am working on this project whihc requires me to fit my experimental data using a complicated function (function is attached in the picture below). May I ask how can I create this fitting function using matlab codes?
Information about function:
function (2):
dependent: A_CC
independent: hbar*omega
parameters: A_1, E_b, E_g, Gamma
function (3):
dependent: A_EC
independent: hbar*omega
parameters: A_2, E_b, E_g, Gamma
Please note that any over lapping terms in both functions should have the same value. For instance, Gamma exist in both (2) and (3), and hence they need to have the same value.
thank you! Hi all,
I am working on this project whihc requires me to fit my experimental data using a complicated function (function is attached in the picture below). May I ask how can I create this fitting function using matlab codes?
Information about function:
function (2):
dependent: A_CC
independent: hbar*omega
parameters: A_1, E_b, E_g, Gamma
function (3):
dependent: A_EC
independent: hbar*omega
parameters: A_2, E_b, E_g, Gamma
Please note that any over lapping terms in both functions should have the same value. For instance, Gamma exist in both (2) and (3), and hence they need to have the same value.
thank you! curve fitting MATLAB Answers — New Questions
Build expert system in Matlab
I’m wondering whether it is possible to create a expert system( Not fuzzy logic ) based on matlab?. Thanks in advanceI’m wondering whether it is possible to create a expert system( Not fuzzy logic ) based on matlab?. Thanks in advance I’m wondering whether it is possible to create a expert system( Not fuzzy logic ) based on matlab?. Thanks in advance expert system MATLAB Answers — New Questions
How do you define the circular mesh feed point on a cylindrical dipole built from primary shapes?
How do you define the circular mesh feedpoint on a cylindrical dipole built from shapes similar to the "Design And Analyze Spherically Capped Biconical Antenna" example. Want to analyze a tubular dipole with end caps extending over the tubes and cannot define a feed point properly like the standard tubular dipole in the Antenna Toolbox.
The feed point affects the radiation pattern and I am too new to Matlab to fix it. Help?How do you define the circular mesh feedpoint on a cylindrical dipole built from shapes similar to the "Design And Analyze Spherically Capped Biconical Antenna" example. Want to analyze a tubular dipole with end caps extending over the tubes and cannot define a feed point properly like the standard tubular dipole in the Antenna Toolbox.
The feed point affects the radiation pattern and I am too new to Matlab to fix it. Help? How do you define the circular mesh feedpoint on a cylindrical dipole built from shapes similar to the "Design And Analyze Spherically Capped Biconical Antenna" example. Want to analyze a tubular dipole with end caps extending over the tubes and cannot define a feed point properly like the standard tubular dipole in the Antenna Toolbox.
The feed point affects the radiation pattern and I am too new to Matlab to fix it. Help? circular mesh, feed point, tubular antenna feed MATLAB Answers — New Questions
lsqnonlin() with Simulink
I am using lsqnonlin() with Simulink as it is used here. I am getting the errors:
Unable to perform assignment because the size of the left side is 30012-by-1 and the size of the right side is 30018-by-1
Error in finitedifferences
Error in computeFinDiffGradAndJac
Here is my code:
function [f] = trackq
% Computes f using lsqnonlin.
mdl = ‘armDynamics’;
open_system(mdl) % Load the model
in = Simulink.SimulationInput(mdl); % Create simulation input object
in = in.setModelParameter(‘StopTime’,’100′); % Stop time 100
f0 = 1; % Initial f
%
options = optimoptions(@lsqnonlin, ‘Algorithm’, ‘levenberg-marquardt’,…
‘Display’,’off’,’StepTolerance’,0.001,’OptimalityTolerance’,0.001);
% Optimize f
set_param(mdl,’FastRestart’,’on’); % Fast restart
% f = lsqnonlin(@compute_error, f0, [], [], options);
f = lsqnonlin(@compute_error, f0, [], [], options);
set_param(mdl,’FastRestart’,’off’);
function error = compute_error(f)
% Set the simulation input object parameters
in = in.setVariable(‘f’, f, ‘Workspace’, mdl);
% Simulate
out = sim(in);
% get q from the actual space arm
armCoords = out.qArm.signals.values;
armCoords = armCoords(2:4);
armCoords = armCoords’;
% get q from modelled space arm
qsim = out.get(‘yout’);
qsim = qsim.getElement(1);
qsim = qsim.Values;
qsim = qsim.Data;
qsim = qsim’;
error = armCoords – qsim;
end
endI am using lsqnonlin() with Simulink as it is used here. I am getting the errors:
Unable to perform assignment because the size of the left side is 30012-by-1 and the size of the right side is 30018-by-1
Error in finitedifferences
Error in computeFinDiffGradAndJac
Here is my code:
function [f] = trackq
% Computes f using lsqnonlin.
mdl = ‘armDynamics’;
open_system(mdl) % Load the model
in = Simulink.SimulationInput(mdl); % Create simulation input object
in = in.setModelParameter(‘StopTime’,’100′); % Stop time 100
f0 = 1; % Initial f
%
options = optimoptions(@lsqnonlin, ‘Algorithm’, ‘levenberg-marquardt’,…
‘Display’,’off’,’StepTolerance’,0.001,’OptimalityTolerance’,0.001);
% Optimize f
set_param(mdl,’FastRestart’,’on’); % Fast restart
% f = lsqnonlin(@compute_error, f0, [], [], options);
f = lsqnonlin(@compute_error, f0, [], [], options);
set_param(mdl,’FastRestart’,’off’);
function error = compute_error(f)
% Set the simulation input object parameters
in = in.setVariable(‘f’, f, ‘Workspace’, mdl);
% Simulate
out = sim(in);
% get q from the actual space arm
armCoords = out.qArm.signals.values;
armCoords = armCoords(2:4);
armCoords = armCoords’;
% get q from modelled space arm
qsim = out.get(‘yout’);
qsim = qsim.getElement(1);
qsim = qsim.Values;
qsim = qsim.Data;
qsim = qsim’;
error = armCoords – qsim;
end
end I am using lsqnonlin() with Simulink as it is used here. I am getting the errors:
Unable to perform assignment because the size of the left side is 30012-by-1 and the size of the right side is 30018-by-1
Error in finitedifferences
Error in computeFinDiffGradAndJac
Here is my code:
function [f] = trackq
% Computes f using lsqnonlin.
mdl = ‘armDynamics’;
open_system(mdl) % Load the model
in = Simulink.SimulationInput(mdl); % Create simulation input object
in = in.setModelParameter(‘StopTime’,’100′); % Stop time 100
f0 = 1; % Initial f
%
options = optimoptions(@lsqnonlin, ‘Algorithm’, ‘levenberg-marquardt’,…
‘Display’,’off’,’StepTolerance’,0.001,’OptimalityTolerance’,0.001);
% Optimize f
set_param(mdl,’FastRestart’,’on’); % Fast restart
% f = lsqnonlin(@compute_error, f0, [], [], options);
f = lsqnonlin(@compute_error, f0, [], [], options);
set_param(mdl,’FastRestart’,’off’);
function error = compute_error(f)
% Set the simulation input object parameters
in = in.setVariable(‘f’, f, ‘Workspace’, mdl);
% Simulate
out = sim(in);
% get q from the actual space arm
armCoords = out.qArm.signals.values;
armCoords = armCoords(2:4);
armCoords = armCoords’;
% get q from modelled space arm
qsim = out.get(‘yout’);
qsim = qsim.getElement(1);
qsim = qsim.Values;
qsim = qsim.Data;
qsim = qsim’;
error = armCoords – qsim;
end
end lsqnonlin MATLAB Answers — New Questions
Bode Plot and resonant peaks
Hello,
I’m trying to fit these points to get a bode plot and possible transfer function
w = [0.1 0.2 0.3 0.5 0.8 1 2 3 5 8 10 20 30 50 80 100 200 300 500 800 1000 2000 3000 5000 8000];
G = [0 0 0 0 0 0 0 10 22 28 33 38 35 33 30 28 20 14 8 0 0 0 0 0 0];
I know there is a zero at 2 and the increasing is steeper so started with
"s^2+4*s+4" on the numerator
I know there is a resonant peak at x = 20 but I’m unable to do it.
Also. how to make the bode plot stop at 0 ?
you can find my try here with this transfer function :H=((s^2+4*s+4))/((s+30)^3);
with C = 6750Hello,
I’m trying to fit these points to get a bode plot and possible transfer function
w = [0.1 0.2 0.3 0.5 0.8 1 2 3 5 8 10 20 30 50 80 100 200 300 500 800 1000 2000 3000 5000 8000];
G = [0 0 0 0 0 0 0 10 22 28 33 38 35 33 30 28 20 14 8 0 0 0 0 0 0];
I know there is a zero at 2 and the increasing is steeper so started with
"s^2+4*s+4" on the numerator
I know there is a resonant peak at x = 20 but I’m unable to do it.
Also. how to make the bode plot stop at 0 ?
you can find my try here with this transfer function :H=((s^2+4*s+4))/((s+30)^3);
with C = 6750 Hello,
I’m trying to fit these points to get a bode plot and possible transfer function
w = [0.1 0.2 0.3 0.5 0.8 1 2 3 5 8 10 20 30 50 80 100 200 300 500 800 1000 2000 3000 5000 8000];
G = [0 0 0 0 0 0 0 10 22 28 33 38 35 33 30 28 20 14 8 0 0 0 0 0 0];
I know there is a zero at 2 and the increasing is steeper so started with
"s^2+4*s+4" on the numerator
I know there is a resonant peak at x = 20 but I’m unable to do it.
Also. how to make the bode plot stop at 0 ?
you can find my try here with this transfer function :H=((s^2+4*s+4))/((s+30)^3);
with C = 6750 bode plot, transfer function, resonant peak, points MATLAB Answers — New Questions
Unable to open custom file while building model in Linux
I’m trying to build a model in Linux environment. But it throws error as unable to open source file. This error is for a custom header file, which is verified to be present in the path (not current path).
I have tried to build the same model in Windows environment, where is builds without any issues.
Does anyone have solution to this problem? Thanks in advance.
P.S. I’m using MATLAB R2022b.I’m trying to build a model in Linux environment. But it throws error as unable to open source file. This error is for a custom header file, which is verified to be present in the path (not current path).
I have tried to build the same model in Windows environment, where is builds without any issues.
Does anyone have solution to this problem? Thanks in advance.
P.S. I’m using MATLAB R2022b. I’m trying to build a model in Linux environment. But it throws error as unable to open source file. This error is for a custom header file, which is verified to be present in the path (not current path).
I have tried to build the same model in Windows environment, where is builds without any issues.
Does anyone have solution to this problem? Thanks in advance.
P.S. I’m using MATLAB R2022b. linux, custom file MATLAB Answers — New Questions
Hessian matrix produced by fmininuc
Dear Sir/Madam:
fminunc is producing a Hessian matrix such that, when I take its Cholesky factor:
[CF,pp]=chol(Hessian);
I get that pp>0. Is there a way to force the algorithm to produce a Hessian such that pp=0?
Many thanks !
Best wishes,
Luca BenatiDear Sir/Madam:
fminunc is producing a Hessian matrix such that, when I take its Cholesky factor:
[CF,pp]=chol(Hessian);
I get that pp>0. Is there a way to force the algorithm to produce a Hessian such that pp=0?
Many thanks !
Best wishes,
Luca Benati Dear Sir/Madam:
fminunc is producing a Hessian matrix such that, when I take its Cholesky factor:
[CF,pp]=chol(Hessian);
I get that pp>0. Is there a way to force the algorithm to produce a Hessian such that pp=0?
Many thanks !
Best wishes,
Luca Benati fiminunc, hessian matrix MATLAB Answers — New Questions
Why do I get “Ignoring extra legend entries” evein in such trivial case?
Hello everyone,
MATLAB never misses on destroying any confidence you have in you coding skills.
I am coding a relatively easy script for data analysis, where I would plot data with a legend. In the code, I loop a plot() function to stack lines and then I ask to display a legend. However, I get the classic error from MATLAB:
Warning: Ignoring extra legend entries.
> In legend>process_inputs (line 590)
In legend>make_legend (line 319)
In legend (line 263)
Without dumping here the entire code, which is redundant, I get the same warning in an analogous and much simpler case:
figure;
x = 1:10;
y = randn(5, 10);
Labs = ["1", "2", "3", "4", "5"];
for i = 1:5
plot(x, y(i,:)); hold on
end
legend(Labs)
The result is 5 lines in the plot, but MATLAB throws the warning above, displaying an empty legend in the figure.
If I try instead the "DislayName" method, the warning disappears, but the legend doesn’t even show up.
figure;
x = 1:10;
y = randn(5, 10);
Labs = ["1", "2", "3", "4", "5"];
for i = 1:5
plot(x, y(i,:), "DisplayName", Labs{i}); hold on
end
legend
Can someone please help make sense of this? Thank you very much in advance.Hello everyone,
MATLAB never misses on destroying any confidence you have in you coding skills.
I am coding a relatively easy script for data analysis, where I would plot data with a legend. In the code, I loop a plot() function to stack lines and then I ask to display a legend. However, I get the classic error from MATLAB:
Warning: Ignoring extra legend entries.
> In legend>process_inputs (line 590)
In legend>make_legend (line 319)
In legend (line 263)
Without dumping here the entire code, which is redundant, I get the same warning in an analogous and much simpler case:
figure;
x = 1:10;
y = randn(5, 10);
Labs = ["1", "2", "3", "4", "5"];
for i = 1:5
plot(x, y(i,:)); hold on
end
legend(Labs)
The result is 5 lines in the plot, but MATLAB throws the warning above, displaying an empty legend in the figure.
If I try instead the "DislayName" method, the warning disappears, but the legend doesn’t even show up.
figure;
x = 1:10;
y = randn(5, 10);
Labs = ["1", "2", "3", "4", "5"];
for i = 1:5
plot(x, y(i,:), "DisplayName", Labs{i}); hold on
end
legend
Can someone please help make sense of this? Thank you very much in advance. Hello everyone,
MATLAB never misses on destroying any confidence you have in you coding skills.
I am coding a relatively easy script for data analysis, where I would plot data with a legend. In the code, I loop a plot() function to stack lines and then I ask to display a legend. However, I get the classic error from MATLAB:
Warning: Ignoring extra legend entries.
> In legend>process_inputs (line 590)
In legend>make_legend (line 319)
In legend (line 263)
Without dumping here the entire code, which is redundant, I get the same warning in an analogous and much simpler case:
figure;
x = 1:10;
y = randn(5, 10);
Labs = ["1", "2", "3", "4", "5"];
for i = 1:5
plot(x, y(i,:)); hold on
end
legend(Labs)
The result is 5 lines in the plot, but MATLAB throws the warning above, displaying an empty legend in the figure.
If I try instead the "DislayName" method, the warning disappears, but the legend doesn’t even show up.
figure;
x = 1:10;
y = randn(5, 10);
Labs = ["1", "2", "3", "4", "5"];
for i = 1:5
plot(x, y(i,:), "DisplayName", Labs{i}); hold on
end
legend
Can someone please help make sense of this? Thank you very much in advance. legend, plot, loop MATLAB Answers — New Questions
Saving of MATLAB Image File not consistent
I have written a code to generate several plots from an array of data. Whenever I am trying to save those image files by savefig (for .fig Matlab files) or by saveas as jpeg or eps format, the saving of the image files is inconsistent. For a group of plots, savefig(‘FileName.fig’) and saveas(gcf,’FileNameeps’,’eps’) are working, i.e., images are saved in the current folder. However, sometimes the newly generated plots are not overwriting the previously generated plots (for some other runs) in the folder.
I have tried including the following before each plot:
delete FileName FileNameeps
But the problem persists. Only when I manually delete all the previous image files from the previous runs for the current folder, newer plots are saved. What can be a fix? Such problem did not occur when I had to generate fewer plots (as in codes generating one dozen plots in stead of some 4 dozen plots)
Thanks in advance.I have written a code to generate several plots from an array of data. Whenever I am trying to save those image files by savefig (for .fig Matlab files) or by saveas as jpeg or eps format, the saving of the image files is inconsistent. For a group of plots, savefig(‘FileName.fig’) and saveas(gcf,’FileNameeps’,’eps’) are working, i.e., images are saved in the current folder. However, sometimes the newly generated plots are not overwriting the previously generated plots (for some other runs) in the folder.
I have tried including the following before each plot:
delete FileName FileNameeps
But the problem persists. Only when I manually delete all the previous image files from the previous runs for the current folder, newer plots are saved. What can be a fix? Such problem did not occur when I had to generate fewer plots (as in codes generating one dozen plots in stead of some 4 dozen plots)
Thanks in advance. I have written a code to generate several plots from an array of data. Whenever I am trying to save those image files by savefig (for .fig Matlab files) or by saveas as jpeg or eps format, the saving of the image files is inconsistent. For a group of plots, savefig(‘FileName.fig’) and saveas(gcf,’FileNameeps’,’eps’) are working, i.e., images are saved in the current folder. However, sometimes the newly generated plots are not overwriting the previously generated plots (for some other runs) in the folder.
I have tried including the following before each plot:
delete FileName FileNameeps
But the problem persists. Only when I manually delete all the previous image files from the previous runs for the current folder, newer plots are saved. What can be a fix? Such problem did not occur when I had to generate fewer plots (as in codes generating one dozen plots in stead of some 4 dozen plots)
Thanks in advance. matlab plots, savefig, saveas MATLAB Answers — New Questions
How do I change the format of symbolic output
When I type:
>> syms x y
>> solve(y-x^2,x)
I get:
ans =
[ 1/2 ]
[y ]
[ ]
[ 1/2]
[-y ]
How do I change the output format so to get MATLAB code (with * and ^), which by the way is what I used to get (before today)?When I type:
>> syms x y
>> solve(y-x^2,x)
I get:
ans =
[ 1/2 ]
[y ]
[ ]
[ 1/2]
[-y ]
How do I change the output format so to get MATLAB code (with * and ^), which by the way is what I used to get (before today)? When I type:
>> syms x y
>> solve(y-x^2,x)
I get:
ans =
[ 1/2 ]
[y ]
[ ]
[ 1/2]
[-y ]
How do I change the output format so to get MATLAB code (with * and ^), which by the way is what I used to get (before today)? output format MATLAB Answers — New Questions
Implementing a seismic source
Dear all,
I’m a new matlab user and I need to create a seismic pulse which the emitting source is moving (time dependent).
I have no idea how to do it.
Thanks in advance for your help.Dear all,
I’m a new matlab user and I need to create a seismic pulse which the emitting source is moving (time dependent).
I have no idea how to do it.
Thanks in advance for your help. Dear all,
I’m a new matlab user and I need to create a seismic pulse which the emitting source is moving (time dependent).
I have no idea how to do it.
Thanks in advance for your help. seismic sources, seismic pulse, seismic emitting source, source level MATLAB Answers — New Questions
Matlab code for Optimization of Distributed Generation
Matlab code for Optimization of Distributed GenerationMatlab code for Optimization of Distributed Generation Matlab code for Optimization of Distributed Generation code, graph MATLAB Answers — New Questions
CUDA Error: Illegal Memory Access in MATLAB Code
Hi everyone,
I’m encountering a CUDA error in my MATLAB code during the second iteration of a loop. Specifically, the error occurs at the wait(gd); command after calling setConstantMemory(kPAM, ‘g_nT_Start’, single((i) * Max_T_dim));. The error message is:
Error using parallel.gpu.CUDADevice/wait
Encountered unexpected error during CUDA execution. The CUDA error was:
an illegal memory access was encountered
Here is the relevant part of my code:
kPAM = parallel.gpu.CUDAKernel(‘PAM.ptx’, ‘PAM.cu’, ‘_PAM’);
kPAM.ThreadBlockSize = [1024,1,1];
kPAM.GridSize = [ceil(struct_GPU.Pix.nTdim/kPAM.ThreadBlockSize(1)),struct_GPU.Pix.nYdim*struct_GPU.Pix.nXdim, struct_GPU.Pix.nZdim];
setConstantMemory(kPAM,’g_nT_Start’,single(0));
for i = 1:Lteration
if i == Lteration % Last iteration
last_T_dim = struct_GPU.Pix.nTdim – (Max_T_dim * i);
last_input_Array = gpuArray(single(zeros(last_T_dim, struct_GPU.Pix.nZdim, …
struct_GPU.Pix.nXdim * struct_GPU.Pix.nYdim)));
assignin(‘base’, ‘PAM_txyz_gpu’, last_input_Array);
assignin(‘base’, ‘PAM_txyz_cpu’, last_input_Array);
elseif i > 1
PAM_txyz_gpu = input_Array;
PAM_txyz_cpu = output_Array;
else
PAM_txyz_gpu = input_Array;
PAM_txyz_cpu = output_Array;
end
[PAM_txyz_gpu] = feval(kPAM, PAM_txyz_gpu, RFData_gpu);
setConstantMemory(kPAM, ‘g_nT_Start’, single((i) * Max_T_dim));
wait(gd);
PAM_txyz_cpu = gather(PAM_txyz_gpu);
wait(gd);
PAM_xyz_cpu = PAM_xyz_cpu + squeeze(sum(PAM_txyz_cpu, 1));
end
clear PAM_txyz_cpu PAM_txyz_gpu last_input_Array input_Array;
reset(gd);
Does anyone have any suggestions on how to resolve this illegal memory access issue?
Thanks in advance!Hi everyone,
I’m encountering a CUDA error in my MATLAB code during the second iteration of a loop. Specifically, the error occurs at the wait(gd); command after calling setConstantMemory(kPAM, ‘g_nT_Start’, single((i) * Max_T_dim));. The error message is:
Error using parallel.gpu.CUDADevice/wait
Encountered unexpected error during CUDA execution. The CUDA error was:
an illegal memory access was encountered
Here is the relevant part of my code:
kPAM = parallel.gpu.CUDAKernel(‘PAM.ptx’, ‘PAM.cu’, ‘_PAM’);
kPAM.ThreadBlockSize = [1024,1,1];
kPAM.GridSize = [ceil(struct_GPU.Pix.nTdim/kPAM.ThreadBlockSize(1)),struct_GPU.Pix.nYdim*struct_GPU.Pix.nXdim, struct_GPU.Pix.nZdim];
setConstantMemory(kPAM,’g_nT_Start’,single(0));
for i = 1:Lteration
if i == Lteration % Last iteration
last_T_dim = struct_GPU.Pix.nTdim – (Max_T_dim * i);
last_input_Array = gpuArray(single(zeros(last_T_dim, struct_GPU.Pix.nZdim, …
struct_GPU.Pix.nXdim * struct_GPU.Pix.nYdim)));
assignin(‘base’, ‘PAM_txyz_gpu’, last_input_Array);
assignin(‘base’, ‘PAM_txyz_cpu’, last_input_Array);
elseif i > 1
PAM_txyz_gpu = input_Array;
PAM_txyz_cpu = output_Array;
else
PAM_txyz_gpu = input_Array;
PAM_txyz_cpu = output_Array;
end
[PAM_txyz_gpu] = feval(kPAM, PAM_txyz_gpu, RFData_gpu);
setConstantMemory(kPAM, ‘g_nT_Start’, single((i) * Max_T_dim));
wait(gd);
PAM_txyz_cpu = gather(PAM_txyz_gpu);
wait(gd);
PAM_xyz_cpu = PAM_xyz_cpu + squeeze(sum(PAM_txyz_cpu, 1));
end
clear PAM_txyz_cpu PAM_txyz_gpu last_input_Array input_Array;
reset(gd);
Does anyone have any suggestions on how to resolve this illegal memory access issue?
Thanks in advance! Hi everyone,
I’m encountering a CUDA error in my MATLAB code during the second iteration of a loop. Specifically, the error occurs at the wait(gd); command after calling setConstantMemory(kPAM, ‘g_nT_Start’, single((i) * Max_T_dim));. The error message is:
Error using parallel.gpu.CUDADevice/wait
Encountered unexpected error during CUDA execution. The CUDA error was:
an illegal memory access was encountered
Here is the relevant part of my code:
kPAM = parallel.gpu.CUDAKernel(‘PAM.ptx’, ‘PAM.cu’, ‘_PAM’);
kPAM.ThreadBlockSize = [1024,1,1];
kPAM.GridSize = [ceil(struct_GPU.Pix.nTdim/kPAM.ThreadBlockSize(1)),struct_GPU.Pix.nYdim*struct_GPU.Pix.nXdim, struct_GPU.Pix.nZdim];
setConstantMemory(kPAM,’g_nT_Start’,single(0));
for i = 1:Lteration
if i == Lteration % Last iteration
last_T_dim = struct_GPU.Pix.nTdim – (Max_T_dim * i);
last_input_Array = gpuArray(single(zeros(last_T_dim, struct_GPU.Pix.nZdim, …
struct_GPU.Pix.nXdim * struct_GPU.Pix.nYdim)));
assignin(‘base’, ‘PAM_txyz_gpu’, last_input_Array);
assignin(‘base’, ‘PAM_txyz_cpu’, last_input_Array);
elseif i > 1
PAM_txyz_gpu = input_Array;
PAM_txyz_cpu = output_Array;
else
PAM_txyz_gpu = input_Array;
PAM_txyz_cpu = output_Array;
end
[PAM_txyz_gpu] = feval(kPAM, PAM_txyz_gpu, RFData_gpu);
setConstantMemory(kPAM, ‘g_nT_Start’, single((i) * Max_T_dim));
wait(gd);
PAM_txyz_cpu = gather(PAM_txyz_gpu);
wait(gd);
PAM_xyz_cpu = PAM_xyz_cpu + squeeze(sum(PAM_txyz_cpu, 1));
end
clear PAM_txyz_cpu PAM_txyz_gpu last_input_Array input_Array;
reset(gd);
Does anyone have any suggestions on how to resolve this illegal memory access issue?
Thanks in advance! gpu, cuda, ptx MATLAB Answers — New Questions
State 에서의 AUTOSAR server runnable 호출 방법
안녕하세요.
AUTOSAR Application SWC 를 MBD 로 구현하고자 하는데 state 내에서의 server runnable 호출을 하려면 어떻게 해야 하는지요?
state 내에 단순히 함수명을 이용한 호출을 시도하면 아래와 같은 오류가 발생합니다.
"AUTOSAR operation ‘AuxH_SnsrRlyCtrl_SetMode’ requires changes to the Simulink Function prototype that cannot be applied to ‘StateHandler/R_StateHandler_10ms_sys/IFCU_State’. For AUTOSAR targets, changes to the Simulink Function prototype are only supported for ‘Simulink Function’ or ‘Function Caller’ blocks in the top model."
특정 state 에서만 server runnable 을 호출하고자 할 때 어떤 방법을 사용하면 되는지 가이드 부탁 드립니다.
감사합니다.안녕하세요.
AUTOSAR Application SWC 를 MBD 로 구현하고자 하는데 state 내에서의 server runnable 호출을 하려면 어떻게 해야 하는지요?
state 내에 단순히 함수명을 이용한 호출을 시도하면 아래와 같은 오류가 발생합니다.
"AUTOSAR operation ‘AuxH_SnsrRlyCtrl_SetMode’ requires changes to the Simulink Function prototype that cannot be applied to ‘StateHandler/R_StateHandler_10ms_sys/IFCU_State’. For AUTOSAR targets, changes to the Simulink Function prototype are only supported for ‘Simulink Function’ or ‘Function Caller’ blocks in the top model."
특정 state 에서만 server runnable 을 호출하고자 할 때 어떤 방법을 사용하면 되는지 가이드 부탁 드립니다.
감사합니다. 안녕하세요.
AUTOSAR Application SWC 를 MBD 로 구현하고자 하는데 state 내에서의 server runnable 호출을 하려면 어떻게 해야 하는지요?
state 내에 단순히 함수명을 이용한 호출을 시도하면 아래와 같은 오류가 발생합니다.
"AUTOSAR operation ‘AuxH_SnsrRlyCtrl_SetMode’ requires changes to the Simulink Function prototype that cannot be applied to ‘StateHandler/R_StateHandler_10ms_sys/IFCU_State’. For AUTOSAR targets, changes to the Simulink Function prototype are only supported for ‘Simulink Function’ or ‘Function Caller’ blocks in the top model."
특정 state 에서만 server runnable 을 호출하고자 할 때 어떤 방법을 사용하면 되는지 가이드 부탁 드립니다.
감사합니다. autosar, stateflow MATLAB Answers — New Questions