Tag Archives: matlab
Sort Internal Variables in FMU
Hi,
I am exporting a Simulink model with some pre-defined internal variables as a FMU. There are properly exported. However, the order is not respected; they seem to be randomly sorted inside the FMU object.
Is there any way I could solve this issue?
Thank you very much in advance.
Best regards,
Víctor Sánchez SuárezHi,
I am exporting a Simulink model with some pre-defined internal variables as a FMU. There are properly exported. However, the order is not respected; they seem to be randomly sorted inside the FMU object.
Is there any way I could solve this issue?
Thank you very much in advance.
Best regards,
Víctor Sánchez Suárez Hi,
I am exporting a Simulink model with some pre-defined internal variables as a FMU. There are properly exported. However, the order is not respected; they seem to be randomly sorted inside the FMU object.
Is there any way I could solve this issue?
Thank you very much in advance.
Best regards,
Víctor Sánchez Suárez fmu, simulink, internal variables, export MATLAB Answers — New Questions
How do I migrate my command history data from older releases to MATLAB R2025a?
How do I migrate my command history data from older releases to MATLAB R2025a?How do I migrate my command history data from older releases to MATLAB R2025a? How do I migrate my command history data from older releases to MATLAB R2025a? command_history, command_history_migration, new_desktop MATLAB Answers — New Questions
How to write single Script for all profiles ?
The input in my case is the measurement data from a sensor doing spiral scanning. So I have 3D point data (x, y, z) of the surface for different geometries like hemisphere, plane, sphere, and cylinder. The script should preprocess this data (filtering, centering, vertex search), fit the right model (sphere, plane, cylinder, or freeform), and then output the fitted parameters along with residuals. The outcomes I want are both numerical results (fit parameters and errors) and visualizations in 2D cross-sections and 3D surface plots.The input in my case is the measurement data from a sensor doing spiral scanning. So I have 3D point data (x, y, z) of the surface for different geometries like hemisphere, plane, sphere, and cylinder. The script should preprocess this data (filtering, centering, vertex search), fit the right model (sphere, plane, cylinder, or freeform), and then output the fitted parameters along with residuals. The outcomes I want are both numerical results (fit parameters and errors) and visualizations in 2D cross-sections and 3D surface plots. The input in my case is the measurement data from a sensor doing spiral scanning. So I have 3D point data (x, y, z) of the surface for different geometries like hemisphere, plane, sphere, and cylinder. The script should preprocess this data (filtering, centering, vertex search), fit the right model (sphere, plane, cylinder, or freeform), and then output the fitted parameters along with residuals. The outcomes I want are both numerical results (fit parameters and errors) and visualizations in 2D cross-sections and 3D surface plots. measurement, sensor, spiral, scan, preprocess, fit, residuals, 2d, 3d, surface MATLAB Answers — New Questions
How can I cross-compile a standalone FMU that I exported from Simulink with Simulink Compiler?
I would like to reuse a standalone FMU generated with Simulink Compiler on another platform. For example, adding Linux binaries when a Simulink model is exported to FMU on Windows platform.I would like to reuse a standalone FMU generated with Simulink Compiler on another platform. For example, adding Linux binaries when a Simulink model is exported to FMU on Windows platform. I would like to reuse a standalone FMU generated with Simulink Compiler on another platform. For example, adding Linux binaries when a Simulink model is exported to FMU on Windows platform. savesourcecodetofmu, cross-compile, codegen MATLAB Answers — New Questions
How can I protect my system from unsafe Model/Block Callbacks
I experiment on thousands of external Simulink models for my research projects. When dealing with them, e.g., performing load_system(<model>) , how can I protect my system from malicious callbacks? Of course I can do a set_param(<model>/<blocks>, <CallBackFcn>, ”) for the model and every block, but only after loading it, though? This means all "LoadFcn" will be executed, up and including a potential rm -rf ~/* or whatever creative malicious code might be hidden somewhere in the model. On open_model(<model>) the "OpenFcn" will be executed similarly.
Is there a sandbox functionality to deal with this attack vector?I experiment on thousands of external Simulink models for my research projects. When dealing with them, e.g., performing load_system(<model>) , how can I protect my system from malicious callbacks? Of course I can do a set_param(<model>/<blocks>, <CallBackFcn>, ”) for the model and every block, but only after loading it, though? This means all "LoadFcn" will be executed, up and including a potential rm -rf ~/* or whatever creative malicious code might be hidden somewhere in the model. On open_model(<model>) the "OpenFcn" will be executed similarly.
Is there a sandbox functionality to deal with this attack vector? I experiment on thousands of external Simulink models for my research projects. When dealing with them, e.g., performing load_system(<model>) , how can I protect my system from malicious callbacks? Of course I can do a set_param(<model>/<blocks>, <CallBackFcn>, ”) for the model and every block, but only after loading it, though? This means all "LoadFcn" will be executed, up and including a potential rm -rf ~/* or whatever creative malicious code might be hidden somewhere in the model. On open_model(<model>) the "OpenFcn" will be executed similarly.
Is there a sandbox functionality to deal with this attack vector? callback, sandbox, trust, safeness MATLAB Answers — New Questions
Unable to read .bin data from Jetson
I am try to run a matched Filter function on jetson, using the ‘exe’ library, but there is no data inside the .bin file that i have generated.
here is the matched filter fucntion
function mf_output = matched_Filter_GPU(rx_signal_noisy, matched_filter, NsampPRI,Npulses) %#codegen
coder.gpu.kernelfun;
rx_signal_noisy1 = (rx_signal_noisy); (rx_signal (1×100000 complex double )
matched_filter1 = (matched_filter); (matched_filter 1×100 complex double)
RX_matrix = reshape(rx_signal_noisy1, NsampPRI, Npulses);
mf_output = conv2(RX_matrix, matched_filter1, ‘same’);
end
here is the wrapper function
function matched_Filter_wrapper(rx_signal_noisy, matched_filter, NsampPRI, Npulses) %#codegen
coder.gpu.kernelfun;
coder.extrinsic(‘fopen’,’fwrite’,’fclose’);
mf_output = matched_Filter_GPU(rx_signal_noisy, matched_filter, NsampPRI, Npulses);
fid = fopen(‘output_new.bin’, ‘w’);
fwrite(fid, [1000 100], ‘int32’);
fwrite(fid, [real(mf_output)], ‘single’)
fclose(fid);
end
here is the MATLAB code
clear
S = load(‘rx_signal_noisy.mat’);
rx_signal_noisy = single(struct2array(S));
S = load(‘MF_coeff.mat’);
MF_coeff = single(struct2array(S));
NsampPRI = int32(1000);
Npulses = int32(100);
hwObj = jetson(‘169.254.172.219′,’hr’,’0000′);
rx_signal_noisy_T = coder.typeof(complex(single(0)), [1 100000], [0 0]);
matched_filter_T = coder.typeof(complex(single(0)), [1 100], [0 0]);
NsampPRI_T = coder.typeof(int32(0), [1 1], [0 0]);
Npulses_T = coder.typeof(int32(0), [1 1], [0 0]);
outfile_T = coder.typeof(‘a’, [1 200], [0 1]);
cfg = coder.gpuConfig(‘exe’);
cfg.Hardware = coder.Hardware(‘NVIDIA Jetson’);
cfg.GenerateReport = false;
cfg.VerificationMode = ‘None’;
cfg.CodeExecutionProfiling = false;
cfg.GenerateExampleMain = ‘GenerateCodeAndCompile’;
cfg.Hardware.BuildDir = ‘~/remoteBuildDir’;
codegen -config cfg matched_Filter_wrapper -args {rx_signal_noisy_T, matched_filter_T, NsampPRI_T, Npulses_T}
system(hwObj, ‘./matched_Filter_wrapper.elf’);
getFile(hwObj, ‘~/remoteBuildDir/MATLAB_ws/R2024a/D/Drive_Data/Radar/Radar/output_new.bin’)
fid = fopen(‘output_new.bin’,’r’);
size1 = fread(fid,2, ‘int32’);
output = fread(fid, prod(NsampPRI), ‘single’);
kindly guide me throigh the process, it will be a great help. thankyou in advanceI am try to run a matched Filter function on jetson, using the ‘exe’ library, but there is no data inside the .bin file that i have generated.
here is the matched filter fucntion
function mf_output = matched_Filter_GPU(rx_signal_noisy, matched_filter, NsampPRI,Npulses) %#codegen
coder.gpu.kernelfun;
rx_signal_noisy1 = (rx_signal_noisy); (rx_signal (1×100000 complex double )
matched_filter1 = (matched_filter); (matched_filter 1×100 complex double)
RX_matrix = reshape(rx_signal_noisy1, NsampPRI, Npulses);
mf_output = conv2(RX_matrix, matched_filter1, ‘same’);
end
here is the wrapper function
function matched_Filter_wrapper(rx_signal_noisy, matched_filter, NsampPRI, Npulses) %#codegen
coder.gpu.kernelfun;
coder.extrinsic(‘fopen’,’fwrite’,’fclose’);
mf_output = matched_Filter_GPU(rx_signal_noisy, matched_filter, NsampPRI, Npulses);
fid = fopen(‘output_new.bin’, ‘w’);
fwrite(fid, [1000 100], ‘int32’);
fwrite(fid, [real(mf_output)], ‘single’)
fclose(fid);
end
here is the MATLAB code
clear
S = load(‘rx_signal_noisy.mat’);
rx_signal_noisy = single(struct2array(S));
S = load(‘MF_coeff.mat’);
MF_coeff = single(struct2array(S));
NsampPRI = int32(1000);
Npulses = int32(100);
hwObj = jetson(‘169.254.172.219′,’hr’,’0000′);
rx_signal_noisy_T = coder.typeof(complex(single(0)), [1 100000], [0 0]);
matched_filter_T = coder.typeof(complex(single(0)), [1 100], [0 0]);
NsampPRI_T = coder.typeof(int32(0), [1 1], [0 0]);
Npulses_T = coder.typeof(int32(0), [1 1], [0 0]);
outfile_T = coder.typeof(‘a’, [1 200], [0 1]);
cfg = coder.gpuConfig(‘exe’);
cfg.Hardware = coder.Hardware(‘NVIDIA Jetson’);
cfg.GenerateReport = false;
cfg.VerificationMode = ‘None’;
cfg.CodeExecutionProfiling = false;
cfg.GenerateExampleMain = ‘GenerateCodeAndCompile’;
cfg.Hardware.BuildDir = ‘~/remoteBuildDir’;
codegen -config cfg matched_Filter_wrapper -args {rx_signal_noisy_T, matched_filter_T, NsampPRI_T, Npulses_T}
system(hwObj, ‘./matched_Filter_wrapper.elf’);
getFile(hwObj, ‘~/remoteBuildDir/MATLAB_ws/R2024a/D/Drive_Data/Radar/Radar/output_new.bin’)
fid = fopen(‘output_new.bin’,’r’);
size1 = fread(fid,2, ‘int32’);
output = fread(fid, prod(NsampPRI), ‘single’);
kindly guide me throigh the process, it will be a great help. thankyou in advance I am try to run a matched Filter function on jetson, using the ‘exe’ library, but there is no data inside the .bin file that i have generated.
here is the matched filter fucntion
function mf_output = matched_Filter_GPU(rx_signal_noisy, matched_filter, NsampPRI,Npulses) %#codegen
coder.gpu.kernelfun;
rx_signal_noisy1 = (rx_signal_noisy); (rx_signal (1×100000 complex double )
matched_filter1 = (matched_filter); (matched_filter 1×100 complex double)
RX_matrix = reshape(rx_signal_noisy1, NsampPRI, Npulses);
mf_output = conv2(RX_matrix, matched_filter1, ‘same’);
end
here is the wrapper function
function matched_Filter_wrapper(rx_signal_noisy, matched_filter, NsampPRI, Npulses) %#codegen
coder.gpu.kernelfun;
coder.extrinsic(‘fopen’,’fwrite’,’fclose’);
mf_output = matched_Filter_GPU(rx_signal_noisy, matched_filter, NsampPRI, Npulses);
fid = fopen(‘output_new.bin’, ‘w’);
fwrite(fid, [1000 100], ‘int32’);
fwrite(fid, [real(mf_output)], ‘single’)
fclose(fid);
end
here is the MATLAB code
clear
S = load(‘rx_signal_noisy.mat’);
rx_signal_noisy = single(struct2array(S));
S = load(‘MF_coeff.mat’);
MF_coeff = single(struct2array(S));
NsampPRI = int32(1000);
Npulses = int32(100);
hwObj = jetson(‘169.254.172.219′,’hr’,’0000′);
rx_signal_noisy_T = coder.typeof(complex(single(0)), [1 100000], [0 0]);
matched_filter_T = coder.typeof(complex(single(0)), [1 100], [0 0]);
NsampPRI_T = coder.typeof(int32(0), [1 1], [0 0]);
Npulses_T = coder.typeof(int32(0), [1 1], [0 0]);
outfile_T = coder.typeof(‘a’, [1 200], [0 1]);
cfg = coder.gpuConfig(‘exe’);
cfg.Hardware = coder.Hardware(‘NVIDIA Jetson’);
cfg.GenerateReport = false;
cfg.VerificationMode = ‘None’;
cfg.CodeExecutionProfiling = false;
cfg.GenerateExampleMain = ‘GenerateCodeAndCompile’;
cfg.Hardware.BuildDir = ‘~/remoteBuildDir’;
codegen -config cfg matched_Filter_wrapper -args {rx_signal_noisy_T, matched_filter_T, NsampPRI_T, Npulses_T}
system(hwObj, ‘./matched_Filter_wrapper.elf’);
getFile(hwObj, ‘~/remoteBuildDir/MATLAB_ws/R2024a/D/Drive_Data/Radar/Radar/output_new.bin’)
fid = fopen(‘output_new.bin’,’r’);
size1 = fread(fid,2, ‘int32’);
output = fread(fid, prod(NsampPRI), ‘single’);
kindly guide me throigh the process, it will be a great help. thankyou in advance nvidia jetson, binary, exe MATLAB Answers — New Questions
Issues in the Structural Design of Injectors
Hi friends!If I know the inlet flow and pressure of the jet pump, as well as the suction port flow and pressure, can I use MATLAB’s jet pump function to obtain the detailed structural dimensions of the jet pump?Hi friends!If I know the inlet flow and pressure of the jet pump, as well as the suction port flow and pressure, can I use MATLAB’s jet pump function to obtain the detailed structural dimensions of the jet pump? Hi friends!If I know the inlet flow and pressure of the jet pump, as well as the suction port flow and pressure, can I use MATLAB’s jet pump function to obtain the detailed structural dimensions of the jet pump? jet pump MATLAB Answers — New Questions
Issues with nlinfit – not fitting second parameter? Fitting a Blackbody curve
Hello all,
I have code to fit a curve to a set of data (a black body curve). I used nlinfit so I could extract errors on the fitted parameters, but I can’t seem to get the second parameter to be considered?
I should end up with a set of 50 plots for the fits, and then a final plot showing luminosity, temp and radius over time. However, the temp over time plot is just displaying the initial value for nlinfit.
Any ideas on what I am doing wrong here?
%errors and fitting of BB function
%constants needed for BB equation
% SI UNITS
c=2.998e8;
h=6.6261e-34;
kb=1.38e-23;
%wavelengths, x data
x = [0.000000212 0.000000231 0.000000291 3.465E-07 3.543E-07 0.000000365 0.000000445 0.000000477 0.000000551 6.231E-07 0.000000658 7.625E-07 0.000000806 9.134E-07 0.00000163];
%flux densities at one epoch (each row is an epoch).
intvaluesallSED = readmatrix("int_values_allSED_3.xlsx");
results = zeros(50,8);
for i = 1:size(intvaluesallSED,1)
flux_den_uncorrected = intvaluesallSED(i,:);
flux_den = flux_den_uncorrected – [3.044257148 2.764380323 1.849636489 1.578043671 1.551640889 1.518279132 1.295492704 1.195475706 0.975440567 0.82279158 0.761751691 0.606214695 0.552059178 0.443122732 0.168971244];
%convert flux den to fv (in SI units)
fv = 3.631e-23.*exp(-0.921034.*flux_den);
%convert fv to f_lambda
f_lambda = fv.*(c./(x.^2));
%for plotting use lambda*f_lambda – y data
y = x.*f_lambda;
%plot figure with data
figure
plot(x, y, ‘o’, ‘MarkerFaceColor’, ‘b’, ‘MarkerSize’, 5);
xlabel(‘Wavelength (m)’);
ylabel(‘lambdaf_lambda’);
%BB function and fit. Here b1 is the aplha multiplication factor and b2 is
%temp. Multiplied by wavelength(xdata) as plotted with lambda*f_lambda
BBfun = @(b,x) (b(1)).*x.*(2.*pi.*h.*(c^2)./(x.^5)).*(1./(exp((h.*c)./(x.*kb.*b(2)))-1));
beta0 = [2.2e-27 ;3e4];
[beta,R,J,CovB,MSE,ErrorModelInfo] = nlinfit(x,y,BBfun,beta0);
%Output values and errors
% b1 is alplha multiplication factor = (R/D)^2, detnoted A. b2 is temp
ci = nlparci(beta,R,"Covar",CovB);
errA = (((ci(1,2)) – (ci(1,1)))/2);
errTemp = ((ci(2,2) – ci(2,1))/2);
A = ((beta(1,1)));
Temp = beta(2,1);
Rad = sqrt(A)*1.85e+24; %convert to radius, distance to transient 1.85e+24
errRad = Rad*sqrt(((0.5*errA)/A)^2 + (4.19e+22/1.85e+24)^2); %error propagation from aplha and distance
%stephan-boltzmann constant
sb = 5.67e-08;
Lum = (4*pi*Rad^2*sb*Temp^4)*1e7; %in erg/s
errLum = Lum*sqrt((2*errRad/Rad)^2 + (4*errTemp/Temp)^2);
results(i,1) = A;
results(i,2) = errA;
results(i,3) = Rad;
results(i,4) = errRad;
results(i,5) = Temp;
results(i,6) = errTemp;
results(i,7) = Lum;
results(i,8) = errLum;
%plot fit
hold on
plot(x,BBfun(beta,x),’-r’);
hold off
end
%final plots
time = [3.4421, 4.2246, 5.695, 6.6946, 7.0809, 7.2812, 8.8125, 9.6112, 10.6128, 11.5382, 11.6742, 13.3953, 14.7236, 15.6233, 16.7919, 17.0436, 18.7829, 19.1707, 20.6369, 21.7721, 22.1614, 22.1619, 23.1565, 23.1571, 23.7631, 24.2266, 25.2168, 26.1579, 26.7577, 27.4169, 29.7512, 31.5264, 33.9284, 35.2449, 37.2385, 38.8981, 39.1618, 40.3597, 41.1686, 42.1524, 44.2117, 45.8706, 46.9335, 47.2638, 48.4002, 50.1866, 52.4438, 55.7044, 60.2141, 69.4632];
figure
t=tiledlayout(3,1,’TileSpacing’,’none’);
nexttile;
errorbar(time, results(:,7), results(:,8), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Luminosity (erg/s)’)
title(‘Luminosity over time’)
set(gca, ‘YScale’, ‘log’)
ytickformat(‘%.1e’)
ylim([6e41 4e45])
nexttile;
errorbar(time, results(:,3), results(:,4), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Radius (m)’)
%title(‘Radius over time’)
ax2 = gca;
ax2.YAxis.Exponent = 0;
ytickformat(‘%.1e’)
ylim([2.5e11 2.5e13])
nexttile;
errorbar(time, results(:,5), results(:,6), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Temperature (K)’)
%title(‘Temperature over time’)
ax3 = gca;
ax3.YAxis.Exponent = 0;
ytickformat(‘%.1e’)
ylim([0 4e4])
The file needed to run the code is attached as well.Hello all,
I have code to fit a curve to a set of data (a black body curve). I used nlinfit so I could extract errors on the fitted parameters, but I can’t seem to get the second parameter to be considered?
I should end up with a set of 50 plots for the fits, and then a final plot showing luminosity, temp and radius over time. However, the temp over time plot is just displaying the initial value for nlinfit.
Any ideas on what I am doing wrong here?
%errors and fitting of BB function
%constants needed for BB equation
% SI UNITS
c=2.998e8;
h=6.6261e-34;
kb=1.38e-23;
%wavelengths, x data
x = [0.000000212 0.000000231 0.000000291 3.465E-07 3.543E-07 0.000000365 0.000000445 0.000000477 0.000000551 6.231E-07 0.000000658 7.625E-07 0.000000806 9.134E-07 0.00000163];
%flux densities at one epoch (each row is an epoch).
intvaluesallSED = readmatrix("int_values_allSED_3.xlsx");
results = zeros(50,8);
for i = 1:size(intvaluesallSED,1)
flux_den_uncorrected = intvaluesallSED(i,:);
flux_den = flux_den_uncorrected – [3.044257148 2.764380323 1.849636489 1.578043671 1.551640889 1.518279132 1.295492704 1.195475706 0.975440567 0.82279158 0.761751691 0.606214695 0.552059178 0.443122732 0.168971244];
%convert flux den to fv (in SI units)
fv = 3.631e-23.*exp(-0.921034.*flux_den);
%convert fv to f_lambda
f_lambda = fv.*(c./(x.^2));
%for plotting use lambda*f_lambda – y data
y = x.*f_lambda;
%plot figure with data
figure
plot(x, y, ‘o’, ‘MarkerFaceColor’, ‘b’, ‘MarkerSize’, 5);
xlabel(‘Wavelength (m)’);
ylabel(‘lambdaf_lambda’);
%BB function and fit. Here b1 is the aplha multiplication factor and b2 is
%temp. Multiplied by wavelength(xdata) as plotted with lambda*f_lambda
BBfun = @(b,x) (b(1)).*x.*(2.*pi.*h.*(c^2)./(x.^5)).*(1./(exp((h.*c)./(x.*kb.*b(2)))-1));
beta0 = [2.2e-27 ;3e4];
[beta,R,J,CovB,MSE,ErrorModelInfo] = nlinfit(x,y,BBfun,beta0);
%Output values and errors
% b1 is alplha multiplication factor = (R/D)^2, detnoted A. b2 is temp
ci = nlparci(beta,R,"Covar",CovB);
errA = (((ci(1,2)) – (ci(1,1)))/2);
errTemp = ((ci(2,2) – ci(2,1))/2);
A = ((beta(1,1)));
Temp = beta(2,1);
Rad = sqrt(A)*1.85e+24; %convert to radius, distance to transient 1.85e+24
errRad = Rad*sqrt(((0.5*errA)/A)^2 + (4.19e+22/1.85e+24)^2); %error propagation from aplha and distance
%stephan-boltzmann constant
sb = 5.67e-08;
Lum = (4*pi*Rad^2*sb*Temp^4)*1e7; %in erg/s
errLum = Lum*sqrt((2*errRad/Rad)^2 + (4*errTemp/Temp)^2);
results(i,1) = A;
results(i,2) = errA;
results(i,3) = Rad;
results(i,4) = errRad;
results(i,5) = Temp;
results(i,6) = errTemp;
results(i,7) = Lum;
results(i,8) = errLum;
%plot fit
hold on
plot(x,BBfun(beta,x),’-r’);
hold off
end
%final plots
time = [3.4421, 4.2246, 5.695, 6.6946, 7.0809, 7.2812, 8.8125, 9.6112, 10.6128, 11.5382, 11.6742, 13.3953, 14.7236, 15.6233, 16.7919, 17.0436, 18.7829, 19.1707, 20.6369, 21.7721, 22.1614, 22.1619, 23.1565, 23.1571, 23.7631, 24.2266, 25.2168, 26.1579, 26.7577, 27.4169, 29.7512, 31.5264, 33.9284, 35.2449, 37.2385, 38.8981, 39.1618, 40.3597, 41.1686, 42.1524, 44.2117, 45.8706, 46.9335, 47.2638, 48.4002, 50.1866, 52.4438, 55.7044, 60.2141, 69.4632];
figure
t=tiledlayout(3,1,’TileSpacing’,’none’);
nexttile;
errorbar(time, results(:,7), results(:,8), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Luminosity (erg/s)’)
title(‘Luminosity over time’)
set(gca, ‘YScale’, ‘log’)
ytickformat(‘%.1e’)
ylim([6e41 4e45])
nexttile;
errorbar(time, results(:,3), results(:,4), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Radius (m)’)
%title(‘Radius over time’)
ax2 = gca;
ax2.YAxis.Exponent = 0;
ytickformat(‘%.1e’)
ylim([2.5e11 2.5e13])
nexttile;
errorbar(time, results(:,5), results(:,6), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Temperature (K)’)
%title(‘Temperature over time’)
ax3 = gca;
ax3.YAxis.Exponent = 0;
ytickformat(‘%.1e’)
ylim([0 4e4])
The file needed to run the code is attached as well. Hello all,
I have code to fit a curve to a set of data (a black body curve). I used nlinfit so I could extract errors on the fitted parameters, but I can’t seem to get the second parameter to be considered?
I should end up with a set of 50 plots for the fits, and then a final plot showing luminosity, temp and radius over time. However, the temp over time plot is just displaying the initial value for nlinfit.
Any ideas on what I am doing wrong here?
%errors and fitting of BB function
%constants needed for BB equation
% SI UNITS
c=2.998e8;
h=6.6261e-34;
kb=1.38e-23;
%wavelengths, x data
x = [0.000000212 0.000000231 0.000000291 3.465E-07 3.543E-07 0.000000365 0.000000445 0.000000477 0.000000551 6.231E-07 0.000000658 7.625E-07 0.000000806 9.134E-07 0.00000163];
%flux densities at one epoch (each row is an epoch).
intvaluesallSED = readmatrix("int_values_allSED_3.xlsx");
results = zeros(50,8);
for i = 1:size(intvaluesallSED,1)
flux_den_uncorrected = intvaluesallSED(i,:);
flux_den = flux_den_uncorrected – [3.044257148 2.764380323 1.849636489 1.578043671 1.551640889 1.518279132 1.295492704 1.195475706 0.975440567 0.82279158 0.761751691 0.606214695 0.552059178 0.443122732 0.168971244];
%convert flux den to fv (in SI units)
fv = 3.631e-23.*exp(-0.921034.*flux_den);
%convert fv to f_lambda
f_lambda = fv.*(c./(x.^2));
%for plotting use lambda*f_lambda – y data
y = x.*f_lambda;
%plot figure with data
figure
plot(x, y, ‘o’, ‘MarkerFaceColor’, ‘b’, ‘MarkerSize’, 5);
xlabel(‘Wavelength (m)’);
ylabel(‘lambdaf_lambda’);
%BB function and fit. Here b1 is the aplha multiplication factor and b2 is
%temp. Multiplied by wavelength(xdata) as plotted with lambda*f_lambda
BBfun = @(b,x) (b(1)).*x.*(2.*pi.*h.*(c^2)./(x.^5)).*(1./(exp((h.*c)./(x.*kb.*b(2)))-1));
beta0 = [2.2e-27 ;3e4];
[beta,R,J,CovB,MSE,ErrorModelInfo] = nlinfit(x,y,BBfun,beta0);
%Output values and errors
% b1 is alplha multiplication factor = (R/D)^2, detnoted A. b2 is temp
ci = nlparci(beta,R,"Covar",CovB);
errA = (((ci(1,2)) – (ci(1,1)))/2);
errTemp = ((ci(2,2) – ci(2,1))/2);
A = ((beta(1,1)));
Temp = beta(2,1);
Rad = sqrt(A)*1.85e+24; %convert to radius, distance to transient 1.85e+24
errRad = Rad*sqrt(((0.5*errA)/A)^2 + (4.19e+22/1.85e+24)^2); %error propagation from aplha and distance
%stephan-boltzmann constant
sb = 5.67e-08;
Lum = (4*pi*Rad^2*sb*Temp^4)*1e7; %in erg/s
errLum = Lum*sqrt((2*errRad/Rad)^2 + (4*errTemp/Temp)^2);
results(i,1) = A;
results(i,2) = errA;
results(i,3) = Rad;
results(i,4) = errRad;
results(i,5) = Temp;
results(i,6) = errTemp;
results(i,7) = Lum;
results(i,8) = errLum;
%plot fit
hold on
plot(x,BBfun(beta,x),’-r’);
hold off
end
%final plots
time = [3.4421, 4.2246, 5.695, 6.6946, 7.0809, 7.2812, 8.8125, 9.6112, 10.6128, 11.5382, 11.6742, 13.3953, 14.7236, 15.6233, 16.7919, 17.0436, 18.7829, 19.1707, 20.6369, 21.7721, 22.1614, 22.1619, 23.1565, 23.1571, 23.7631, 24.2266, 25.2168, 26.1579, 26.7577, 27.4169, 29.7512, 31.5264, 33.9284, 35.2449, 37.2385, 38.8981, 39.1618, 40.3597, 41.1686, 42.1524, 44.2117, 45.8706, 46.9335, 47.2638, 48.4002, 50.1866, 52.4438, 55.7044, 60.2141, 69.4632];
figure
t=tiledlayout(3,1,’TileSpacing’,’none’);
nexttile;
errorbar(time, results(:,7), results(:,8), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Luminosity (erg/s)’)
title(‘Luminosity over time’)
set(gca, ‘YScale’, ‘log’)
ytickformat(‘%.1e’)
ylim([6e41 4e45])
nexttile;
errorbar(time, results(:,3), results(:,4), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Radius (m)’)
%title(‘Radius over time’)
ax2 = gca;
ax2.YAxis.Exponent = 0;
ytickformat(‘%.1e’)
ylim([2.5e11 2.5e13])
nexttile;
errorbar(time, results(:,5), results(:,6), ‘.’, ‘MarkerSize’, 12)
xlabel(‘Time (MJD-58285)’)
ylabel(‘Temperature (K)’)
%title(‘Temperature over time’)
ax3 = gca;
ax3.YAxis.Exponent = 0;
ytickformat(‘%.1e’)
ylim([0 4e4])
The file needed to run the code is attached as well. nlinfit, nonlinear, astronomy, astrophysics, blackbody, matlab, curve fitting, parameters, fitting, statistics, physics MATLAB Answers — New Questions
Simscape: Constraining Translational Network with Slider Crank Block
Hi,
I am building a Simscape digital twin of a twin-cylinder opposed-piston engine. I am unsure if my basic block configuration is correct to describe a single crankshaft with two opposing cylinders. When the pistons of the left and right cylinders are at their TDC positions (initial conditions set to TDC with peak cylinder pressures) where the crank initial angle should be 270 degrees CA and 90 degrees CA (horizontal), respectively. However, in the model, I need to enter 180 CA and 90 CA, respectively, in an attempt to get reasonable rotation of the crank. I have used an Ideal Angular Velocity Source (94.3 rad/s) in an attempt to help debugging, however, the motion of the slider seems erratic. I will paste a schematic of the crank assembly, and image of the model below. Any help be great, as seem to struggling with what seems like a basic Simscape task of constraining the translational motion of the piston mass with the slider-crank block.
My model uses a simply force input imported directly from the workspace, where the left cylinder force is positive in sign (translating the piston mass to the right), and the right cylinder force is negative in sign (translating the piston mass to the left), and the translational motion is constrained by the crank assemby, with a crank radius of 70 mm (total stroke of 140 mm) and a con rod length of 400 mm, and assumes a rotational speed of 94 rad/s (15 Hz) so a basic model.
Thanks, PatrickHi,
I am building a Simscape digital twin of a twin-cylinder opposed-piston engine. I am unsure if my basic block configuration is correct to describe a single crankshaft with two opposing cylinders. When the pistons of the left and right cylinders are at their TDC positions (initial conditions set to TDC with peak cylinder pressures) where the crank initial angle should be 270 degrees CA and 90 degrees CA (horizontal), respectively. However, in the model, I need to enter 180 CA and 90 CA, respectively, in an attempt to get reasonable rotation of the crank. I have used an Ideal Angular Velocity Source (94.3 rad/s) in an attempt to help debugging, however, the motion of the slider seems erratic. I will paste a schematic of the crank assembly, and image of the model below. Any help be great, as seem to struggling with what seems like a basic Simscape task of constraining the translational motion of the piston mass with the slider-crank block.
My model uses a simply force input imported directly from the workspace, where the left cylinder force is positive in sign (translating the piston mass to the right), and the right cylinder force is negative in sign (translating the piston mass to the left), and the translational motion is constrained by the crank assemby, with a crank radius of 70 mm (total stroke of 140 mm) and a con rod length of 400 mm, and assumes a rotational speed of 94 rad/s (15 Hz) so a basic model.
Thanks, Patrick Hi,
I am building a Simscape digital twin of a twin-cylinder opposed-piston engine. I am unsure if my basic block configuration is correct to describe a single crankshaft with two opposing cylinders. When the pistons of the left and right cylinders are at their TDC positions (initial conditions set to TDC with peak cylinder pressures) where the crank initial angle should be 270 degrees CA and 90 degrees CA (horizontal), respectively. However, in the model, I need to enter 180 CA and 90 CA, respectively, in an attempt to get reasonable rotation of the crank. I have used an Ideal Angular Velocity Source (94.3 rad/s) in an attempt to help debugging, however, the motion of the slider seems erratic. I will paste a schematic of the crank assembly, and image of the model below. Any help be great, as seem to struggling with what seems like a basic Simscape task of constraining the translational motion of the piston mass with the slider-crank block.
My model uses a simply force input imported directly from the workspace, where the left cylinder force is positive in sign (translating the piston mass to the right), and the right cylinder force is negative in sign (translating the piston mass to the left), and the translational motion is constrained by the crank assemby, with a crank radius of 70 mm (total stroke of 140 mm) and a con rod length of 400 mm, and assumes a rotational speed of 94 rad/s (15 Hz) so a basic model.
Thanks, Patrick simscape, simulink MATLAB Answers — New Questions
What Is the Behavior of Symbolic nchoosek With n < 0 ?
According to nchoosek:Algorithms
"If k < 0 or n – k < 0, nchoosek(n,k) returns 0."
syms n k
f(n,k) = nchoosek(n,k)
Using the example at Binomial Coefficients for Numeric and Symbolic Arguments
nn = sym(-7); kk = sym(2);
isAlways(nn – kk < 0)
f(nn,kk)
The result should be 0 according to the algorithms section.
But given that it’s not zero, where did it come from?
Not a simple factorial expression
try
factorial(nn)/factorial(kk)/factorial(nn-kk);
catch ME
ME.message
end
Try an expanded version of f
f(n,k) = expand(f)
The above expression does not match (to the eye) More About.
It also doesn’t yield the original result
f(nn,kk)
Nor does the simplified form (which also doesn’t visually match More About)
f = simplify(f)
f(nn,kk)
Is the doc wrong and symbolic nchoosek(-7,2) should return 28? If so, where does 28 come from?
FWIW, nchoosek is not using abs(n)
f(abs(nn),kk)According to nchoosek:Algorithms
"If k < 0 or n – k < 0, nchoosek(n,k) returns 0."
syms n k
f(n,k) = nchoosek(n,k)
Using the example at Binomial Coefficients for Numeric and Symbolic Arguments
nn = sym(-7); kk = sym(2);
isAlways(nn – kk < 0)
f(nn,kk)
The result should be 0 according to the algorithms section.
But given that it’s not zero, where did it come from?
Not a simple factorial expression
try
factorial(nn)/factorial(kk)/factorial(nn-kk);
catch ME
ME.message
end
Try an expanded version of f
f(n,k) = expand(f)
The above expression does not match (to the eye) More About.
It also doesn’t yield the original result
f(nn,kk)
Nor does the simplified form (which also doesn’t visually match More About)
f = simplify(f)
f(nn,kk)
Is the doc wrong and symbolic nchoosek(-7,2) should return 28? If so, where does 28 come from?
FWIW, nchoosek is not using abs(n)
f(abs(nn),kk) According to nchoosek:Algorithms
"If k < 0 or n – k < 0, nchoosek(n,k) returns 0."
syms n k
f(n,k) = nchoosek(n,k)
Using the example at Binomial Coefficients for Numeric and Symbolic Arguments
nn = sym(-7); kk = sym(2);
isAlways(nn – kk < 0)
f(nn,kk)
The result should be 0 according to the algorithms section.
But given that it’s not zero, where did it come from?
Not a simple factorial expression
try
factorial(nn)/factorial(kk)/factorial(nn-kk);
catch ME
ME.message
end
Try an expanded version of f
f(n,k) = expand(f)
The above expression does not match (to the eye) More About.
It also doesn’t yield the original result
f(nn,kk)
Nor does the simplified form (which also doesn’t visually match More About)
f = simplify(f)
f(nn,kk)
Is the doc wrong and symbolic nchoosek(-7,2) should return 28? If so, where does 28 come from?
FWIW, nchoosek is not using abs(n)
f(abs(nn),kk) symbolic, nchoosek, negative argument MATLAB Answers — New Questions
How to send data from an RFSoC device to the Host PC?
Dear all,
I am using AMD Zynq Ultrascale+ ZCU111 evaluation board for a simple receiver design.
Currently I record a signal from an ADC and stream it to the processing system using AXI4-Stream to Software. I can generate a bitstream using SoC Builder, run the external mode model and see the recorded signal.
The question is now how to write, e.g., 1ms of this data stream to a file on the host PC? (e.g. for the FPGA algorithm verification)
Thank you!Dear all,
I am using AMD Zynq Ultrascale+ ZCU111 evaluation board for a simple receiver design.
Currently I record a signal from an ADC and stream it to the processing system using AXI4-Stream to Software. I can generate a bitstream using SoC Builder, run the external mode model and see the recorded signal.
The question is now how to write, e.g., 1ms of this data stream to a file on the host PC? (e.g. for the FPGA algorithm verification)
Thank you! Dear all,
I am using AMD Zynq Ultrascale+ ZCU111 evaluation board for a simple receiver design.
Currently I record a signal from an ADC and stream it to the processing system using AXI4-Stream to Software. I can generate a bitstream using SoC Builder, run the external mode model and see the recorded signal.
The question is now how to write, e.g., 1ms of this data stream to a file on the host PC? (e.g. for the FPGA algorithm verification)
Thank you! soc blockset, embedded coder, target hardware, communication, external mode, data transfer, rfsoc, zcu111 MATLAB Answers — New Questions
Parallel processing is not able to use all my cores
I have the same problem.
The SuperMicro MBD-H12DSI-N6-B motherboard has 2 x 48-core AMD EPYC 7K62 processors.
But MATLAB (R2024a) sees only one of them and opens a pool with 48 workers.
When multiplying and inverting matrices, the dual-processor system load is 50…65%.
The operating system is Microsoft Windows 10 Pro for Workstations 22H2.
The maxNumCompThreads command produces the following result:
>> N = maxNumCompThreads
N =
48
An attempt to set the maximum number of workers to 96 succeeds:
>> LASTN = maxNumCompThreads(96)
LASTN =
48
>> N = maxNumCompThreads
N =
96
But after that, a pool is opened with 48 workers as well:
>> parpool
Starting parallel pool (parpool) using the ‘Processes’ profile …
Connected to parallel pool with 48 workers.
ans =
ProcessPool with properties:
Connected: true
NumWorkers: 48
However, I did not find in the settings where I can set the maximum number of workers.
The feature(‘numcores’) command produces the following result:
>> feature(‘numcores’)
MATLAB detected: 96 physical cores.
MATLAB detected: 96 logical cores.
MATLAB was assigned: 48 logical cores by the OS.
MATLAB is using: 48 logical cores.
MATLAB is not using all logical cores because Operating System restricted the number of cores to: 48.
ans =
48
That is, MATLAB complains about the Windows operating system
What to do?
Is it possible to run all 96 cores?I have the same problem.
The SuperMicro MBD-H12DSI-N6-B motherboard has 2 x 48-core AMD EPYC 7K62 processors.
But MATLAB (R2024a) sees only one of them and opens a pool with 48 workers.
When multiplying and inverting matrices, the dual-processor system load is 50…65%.
The operating system is Microsoft Windows 10 Pro for Workstations 22H2.
The maxNumCompThreads command produces the following result:
>> N = maxNumCompThreads
N =
48
An attempt to set the maximum number of workers to 96 succeeds:
>> LASTN = maxNumCompThreads(96)
LASTN =
48
>> N = maxNumCompThreads
N =
96
But after that, a pool is opened with 48 workers as well:
>> parpool
Starting parallel pool (parpool) using the ‘Processes’ profile …
Connected to parallel pool with 48 workers.
ans =
ProcessPool with properties:
Connected: true
NumWorkers: 48
However, I did not find in the settings where I can set the maximum number of workers.
The feature(‘numcores’) command produces the following result:
>> feature(‘numcores’)
MATLAB detected: 96 physical cores.
MATLAB detected: 96 logical cores.
MATLAB was assigned: 48 logical cores by the OS.
MATLAB is using: 48 logical cores.
MATLAB is not using all logical cores because Operating System restricted the number of cores to: 48.
ans =
48
That is, MATLAB complains about the Windows operating system
What to do?
Is it possible to run all 96 cores? I have the same problem.
The SuperMicro MBD-H12DSI-N6-B motherboard has 2 x 48-core AMD EPYC 7K62 processors.
But MATLAB (R2024a) sees only one of them and opens a pool with 48 workers.
When multiplying and inverting matrices, the dual-processor system load is 50…65%.
The operating system is Microsoft Windows 10 Pro for Workstations 22H2.
The maxNumCompThreads command produces the following result:
>> N = maxNumCompThreads
N =
48
An attempt to set the maximum number of workers to 96 succeeds:
>> LASTN = maxNumCompThreads(96)
LASTN =
48
>> N = maxNumCompThreads
N =
96
But after that, a pool is opened with 48 workers as well:
>> parpool
Starting parallel pool (parpool) using the ‘Processes’ profile …
Connected to parallel pool with 48 workers.
ans =
ProcessPool with properties:
Connected: true
NumWorkers: 48
However, I did not find in the settings where I can set the maximum number of workers.
The feature(‘numcores’) command produces the following result:
>> feature(‘numcores’)
MATLAB detected: 96 physical cores.
MATLAB detected: 96 logical cores.
MATLAB was assigned: 48 logical cores by the OS.
MATLAB is using: 48 logical cores.
MATLAB is not using all logical cores because Operating System restricted the number of cores to: 48.
ans =
48
That is, MATLAB complains about the Windows operating system
What to do?
Is it possible to run all 96 cores? parallel processing MATLAB Answers — New Questions
Analytic solution of quatric polynomial does not add up
Dear friends,
I currently ran into a math-issue when trying to get the analytical roots of a polynomial of order 4.
What I want to solve is:
The solution shall run on a microcontroller with dynamically changing parameters [a,d,e]. All parameters are real. I am searching for the real results, imaginary solutions are to be prevented. When applying Matlab symbolic, The parameters [a,d,e] are simplified and represent longer sub-terms. In accordance to the article Wiki: quartic function, I will receive quite a long solution, that is futile to reproduce here. I used the following short code to generate it:
syms x a d e
y= a*x^4+d*x+e
sol=solve(y==0,x,’MaxDegree’,4,’ReturnConditions’,true)
To check the solution, I tested it on an easier sub-problem: When d=0 is chosen follows:
When chosing a>0, e<0 this clearly yields some real results, besides the imaginary ones. Now the problem: the above given long solution cannot reproduce this result. Even if I force assumptions that should solve it, follows something that does not look equal:
syms x a d e
assume(a>=0)
assume(d>=0)
assume(e<=0)
y= a*x^4+d*x+e
sol=solve(y==0,x,’MaxDegree’,4,’ReturnConditions’,true)
testresult=simplify(subs(sol.x, d,0))
latex(testresult)
However, if I change the equation before solving the quartic function, the solution of it looks as on paper:
y= a*x^4+e
assume(a>=0)
assume(d>=0)
assume(e<=0)
sol=solve(y==0,x,’MaxDegree’,4,’ReturnConditions’,true)
testresult2=sol.x
latex(testresult2)
Numerical testing via inserting numbers in the two solutions according to the assumptions a>0, e<0 confirms the difference of the results. Chosing a=1 and e=-2 yields:
1) the general solution of the quartic polynomial (inserting d=0 after solving the quartic polynomial):
vpares1=vpa(subs(testresult,{a,e},{1,-2}))
vpares1 =
0
0
0
0
2) the solution of the simplified quartic polynomial (inserting d=0 before solving):
vpares2=vpa(subs(testresult2,{a,e},{1,-2}))
vpares2 =
1.1892071150027210667174999705605
-1.1892071150027210667174999705605
-1.1892071150027210667174999705605i
1.1892071150027210667174999705605i
Visibly, the trivial solution is not permissible given the solution of case 2). Interestingly, if the requirement is switched from {a>0,e<0} to {a<0, e>0} the solutions match again.
Similar difficulties have shown, when I hand-coded the general solution from the mentioned Wikipedia article. As I need the solution for , I now have trust-issues with the long solution. Therefore, I ask for your help or comment, why the "general solution" does not end in the same result as the simplified problem.
Thank you in advance for your help!Dear friends,
I currently ran into a math-issue when trying to get the analytical roots of a polynomial of order 4.
What I want to solve is:
The solution shall run on a microcontroller with dynamically changing parameters [a,d,e]. All parameters are real. I am searching for the real results, imaginary solutions are to be prevented. When applying Matlab symbolic, The parameters [a,d,e] are simplified and represent longer sub-terms. In accordance to the article Wiki: quartic function, I will receive quite a long solution, that is futile to reproduce here. I used the following short code to generate it:
syms x a d e
y= a*x^4+d*x+e
sol=solve(y==0,x,’MaxDegree’,4,’ReturnConditions’,true)
To check the solution, I tested it on an easier sub-problem: When d=0 is chosen follows:
When chosing a>0, e<0 this clearly yields some real results, besides the imaginary ones. Now the problem: the above given long solution cannot reproduce this result. Even if I force assumptions that should solve it, follows something that does not look equal:
syms x a d e
assume(a>=0)
assume(d>=0)
assume(e<=0)
y= a*x^4+d*x+e
sol=solve(y==0,x,’MaxDegree’,4,’ReturnConditions’,true)
testresult=simplify(subs(sol.x, d,0))
latex(testresult)
However, if I change the equation before solving the quartic function, the solution of it looks as on paper:
y= a*x^4+e
assume(a>=0)
assume(d>=0)
assume(e<=0)
sol=solve(y==0,x,’MaxDegree’,4,’ReturnConditions’,true)
testresult2=sol.x
latex(testresult2)
Numerical testing via inserting numbers in the two solutions according to the assumptions a>0, e<0 confirms the difference of the results. Chosing a=1 and e=-2 yields:
1) the general solution of the quartic polynomial (inserting d=0 after solving the quartic polynomial):
vpares1=vpa(subs(testresult,{a,e},{1,-2}))
vpares1 =
0
0
0
0
2) the solution of the simplified quartic polynomial (inserting d=0 before solving):
vpares2=vpa(subs(testresult2,{a,e},{1,-2}))
vpares2 =
1.1892071150027210667174999705605
-1.1892071150027210667174999705605
-1.1892071150027210667174999705605i
1.1892071150027210667174999705605i
Visibly, the trivial solution is not permissible given the solution of case 2). Interestingly, if the requirement is switched from {a>0,e<0} to {a<0, e>0} the solutions match again.
Similar difficulties have shown, when I hand-coded the general solution from the mentioned Wikipedia article. As I need the solution for , I now have trust-issues with the long solution. Therefore, I ask for your help or comment, why the "general solution" does not end in the same result as the simplified problem.
Thank you in advance for your help! Dear friends,
I currently ran into a math-issue when trying to get the analytical roots of a polynomial of order 4.
What I want to solve is:
The solution shall run on a microcontroller with dynamically changing parameters [a,d,e]. All parameters are real. I am searching for the real results, imaginary solutions are to be prevented. When applying Matlab symbolic, The parameters [a,d,e] are simplified and represent longer sub-terms. In accordance to the article Wiki: quartic function, I will receive quite a long solution, that is futile to reproduce here. I used the following short code to generate it:
syms x a d e
y= a*x^4+d*x+e
sol=solve(y==0,x,’MaxDegree’,4,’ReturnConditions’,true)
To check the solution, I tested it on an easier sub-problem: When d=0 is chosen follows:
When chosing a>0, e<0 this clearly yields some real results, besides the imaginary ones. Now the problem: the above given long solution cannot reproduce this result. Even if I force assumptions that should solve it, follows something that does not look equal:
syms x a d e
assume(a>=0)
assume(d>=0)
assume(e<=0)
y= a*x^4+d*x+e
sol=solve(y==0,x,’MaxDegree’,4,’ReturnConditions’,true)
testresult=simplify(subs(sol.x, d,0))
latex(testresult)
However, if I change the equation before solving the quartic function, the solution of it looks as on paper:
y= a*x^4+e
assume(a>=0)
assume(d>=0)
assume(e<=0)
sol=solve(y==0,x,’MaxDegree’,4,’ReturnConditions’,true)
testresult2=sol.x
latex(testresult2)
Numerical testing via inserting numbers in the two solutions according to the assumptions a>0, e<0 confirms the difference of the results. Chosing a=1 and e=-2 yields:
1) the general solution of the quartic polynomial (inserting d=0 after solving the quartic polynomial):
vpares1=vpa(subs(testresult,{a,e},{1,-2}))
vpares1 =
0
0
0
0
2) the solution of the simplified quartic polynomial (inserting d=0 before solving):
vpares2=vpa(subs(testresult2,{a,e},{1,-2}))
vpares2 =
1.1892071150027210667174999705605
-1.1892071150027210667174999705605
-1.1892071150027210667174999705605i
1.1892071150027210667174999705605i
Visibly, the trivial solution is not permissible given the solution of case 2). Interestingly, if the requirement is switched from {a>0,e<0} to {a<0, e>0} the solutions match again.
Similar difficulties have shown, when I hand-coded the general solution from the mentioned Wikipedia article. As I need the solution for , I now have trust-issues with the long solution. Therefore, I ask for your help or comment, why the "general solution" does not end in the same result as the simplified problem.
Thank you in advance for your help! mathematics, symbolic, 4th order polynomial, polynomial MATLAB Answers — New Questions
Fatal error starting Matlab 1. time in Ubuntu 25.04
Starting Matlab in CLI on an Ubuntu 25.04 with 16 Gb of RAM I get this:
MATLAB is selecting SOFTWARE OPENGL rendering.
Fontconfig warning: "/usr/share/fontconfig/conf.avail/05-reset-dirs-sample.conf", line 6: unknown element "reset-dirs"
library initialization failed – unable to allocate file descriptor table – out of memory
MATLAB is exiting because of fatal error.
I have installed to /home/pgl/matlab as a user (not su).
What is the issue?
Best
PålStarting Matlab in CLI on an Ubuntu 25.04 with 16 Gb of RAM I get this:
MATLAB is selecting SOFTWARE OPENGL rendering.
Fontconfig warning: "/usr/share/fontconfig/conf.avail/05-reset-dirs-sample.conf", line 6: unknown element "reset-dirs"
library initialization failed – unable to allocate file descriptor table – out of memory
MATLAB is exiting because of fatal error.
I have installed to /home/pgl/matlab as a user (not su).
What is the issue?
Best
Pål Starting Matlab in CLI on an Ubuntu 25.04 with 16 Gb of RAM I get this:
MATLAB is selecting SOFTWARE OPENGL rendering.
Fontconfig warning: "/usr/share/fontconfig/conf.avail/05-reset-dirs-sample.conf", line 6: unknown element "reset-dirs"
library initialization failed – unable to allocate file descriptor table – out of memory
MATLAB is exiting because of fatal error.
I have installed to /home/pgl/matlab as a user (not su).
What is the issue?
Best
Pål ubuntu 25.04, font rendering, opengl MATLAB Answers — New Questions
Errors in listener callbacks
I have an app built in MATLAB App Designer. the underlying code utlizes events and listeners. my problem is this: Whenever an error occurs in the code, the app needs to know about this. when the error occurs in the code itself, there are built in "catch" commands that notify the GUI.
However, when an error occurs in one of the listener callbacks, there is some built in mechanism that replaces the error with a warning. Instead of getting an error message we get a warning: "error occurred during execution of listener callback" and a description of the error message.
Is there a way to cancel this mechanism? to let the errors in listener callbacks become actual error messages? or maybe a way to notify the app in case of a warning? something like try catch that includes warnings?
many thanks
NathanI have an app built in MATLAB App Designer. the underlying code utlizes events and listeners. my problem is this: Whenever an error occurs in the code, the app needs to know about this. when the error occurs in the code itself, there are built in "catch" commands that notify the GUI.
However, when an error occurs in one of the listener callbacks, there is some built in mechanism that replaces the error with a warning. Instead of getting an error message we get a warning: "error occurred during execution of listener callback" and a description of the error message.
Is there a way to cancel this mechanism? to let the errors in listener callbacks become actual error messages? or maybe a way to notify the app in case of a warning? something like try catch that includes warnings?
many thanks
Nathan I have an app built in MATLAB App Designer. the underlying code utlizes events and listeners. my problem is this: Whenever an error occurs in the code, the app needs to know about this. when the error occurs in the code itself, there are built in "catch" commands that notify the GUI.
However, when an error occurs in one of the listener callbacks, there is some built in mechanism that replaces the error with a warning. Instead of getting an error message we get a warning: "error occurred during execution of listener callback" and a description of the error message.
Is there a way to cancel this mechanism? to let the errors in listener callbacks become actual error messages? or maybe a way to notify the app in case of a warning? something like try catch that includes warnings?
many thanks
Nathan app designer, listener, event, callback, error MATLAB Answers — New Questions
DDPG Agent for Battery Control: Scalar action vs Full trajectory?
I’m implementing a Reinforcement Learning solution to control a home battery, similar to a Model Predictive Control (MPC) approach. The observation includes the current state of charge (SoC) and N-step forecasts for PV generation, electrical demand, import price, and export price.
In MPC, I calculate an optimal charge/discharge trajectory over the prediction horizon and output the entire plan. Now, I’m trying to implement the same using a DDPG agent in MATLAB.
My questions:
Should the DDPG agent output a scalar action (charging/discharging power) for each timestep, which is then used to update the SoC based on the sampling time,
or should the agent output a full trajectory, where I execute only the first action but discard the remaining ones, while still using the full trajectory for the reward calculation?
My thoughts:
In MPC, I get the entire optimal trajectory for charging and discharging over the horizon. Initially, I considered using the same approach with the DDPG agent. However, I’m wondering if this is necessary because the value function already accounts for downstream benefits (future prices/loads) since they are included in the state, right?
But if the agent returns just one action for the next state, it seems like this would lead to a result similar to what I would get if I had no prediction horizon at all.
Thanks in advance for any suggestions.I’m implementing a Reinforcement Learning solution to control a home battery, similar to a Model Predictive Control (MPC) approach. The observation includes the current state of charge (SoC) and N-step forecasts for PV generation, electrical demand, import price, and export price.
In MPC, I calculate an optimal charge/discharge trajectory over the prediction horizon and output the entire plan. Now, I’m trying to implement the same using a DDPG agent in MATLAB.
My questions:
Should the DDPG agent output a scalar action (charging/discharging power) for each timestep, which is then used to update the SoC based on the sampling time,
or should the agent output a full trajectory, where I execute only the first action but discard the remaining ones, while still using the full trajectory for the reward calculation?
My thoughts:
In MPC, I get the entire optimal trajectory for charging and discharging over the horizon. Initially, I considered using the same approach with the DDPG agent. However, I’m wondering if this is necessary because the value function already accounts for downstream benefits (future prices/loads) since they are included in the state, right?
But if the agent returns just one action for the next state, it seems like this would lead to a result similar to what I would get if I had no prediction horizon at all.
Thanks in advance for any suggestions. I’m implementing a Reinforcement Learning solution to control a home battery, similar to a Model Predictive Control (MPC) approach. The observation includes the current state of charge (SoC) and N-step forecasts for PV generation, electrical demand, import price, and export price.
In MPC, I calculate an optimal charge/discharge trajectory over the prediction horizon and output the entire plan. Now, I’m trying to implement the same using a DDPG agent in MATLAB.
My questions:
Should the DDPG agent output a scalar action (charging/discharging power) for each timestep, which is then used to update the SoC based on the sampling time,
or should the agent output a full trajectory, where I execute only the first action but discard the remaining ones, while still using the full trajectory for the reward calculation?
My thoughts:
In MPC, I get the entire optimal trajectory for charging and discharging over the horizon. Initially, I considered using the same approach with the DDPG agent. However, I’m wondering if this is necessary because the value function already accounts for downstream benefits (future prices/loads) since they are included in the state, right?
But if the agent returns just one action for the next state, it seems like this would lead to a result similar to what I would get if I had no prediction horizon at all.
Thanks in advance for any suggestions. reinforcement-learning, ddpg, simulink, mpc, matlab MATLAB Answers — New Questions
TreeTable in Matlab 2025a
Since javacomponents are deprecated as of MATLAB 2025a, has anyone found a way to generate treetables similar to what was possible with jide ?
We have been relying on those for a lot of GUI and see nothing in UITABLE/UITREE that would be similar. Necessary features are
tree opening
resizable columns
cell renderer allowing push buttons and pull down menus
column sorting is a bonusSince javacomponents are deprecated as of MATLAB 2025a, has anyone found a way to generate treetables similar to what was possible with jide ?
We have been relying on those for a lot of GUI and see nothing in UITABLE/UITREE that would be similar. Necessary features are
tree opening
resizable columns
cell renderer allowing push buttons and pull down menus
column sorting is a bonus Since javacomponents are deprecated as of MATLAB 2025a, has anyone found a way to generate treetables similar to what was possible with jide ?
We have been relying on those for a lot of GUI and see nothing in UITABLE/UITREE that would be similar. Necessary features are
tree opening
resizable columns
cell renderer allowing push buttons and pull down menus
column sorting is a bonus uitable, uitree, treetable MATLAB Answers — New Questions









