Category: Matlab
Category Archives: Matlab
different color to plot
hi,it’ possible to plot in different color? (example : line color yellow but the last point are colored in black)hi,it’ possible to plot in different color? (example : line color yellow but the last point are colored in black) hi,it’ possible to plot in different color? (example : line color yellow but the last point are colored in black) different color to plot MATLAB Answers — New Questions
Error with matrix calculation
% matrix calculation
M3 = [0 0 0 0 -1 0 0 0 0 0 1 0;
0 0 0 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 -0.05 1;
1 0 0 0 0 0 0 0 -1 0 -1 0;
0 -1 0 0 0 0 0 0 0 -1 0 0;
-0.15 0 0 0 0 0 0 0 -0.15 0 0.05 0;
-1 0 1 0 0 0 0 0 0 0 0 0;
0 1 0 1 0 0 0 0 0 0 0 0;
-0.4*sind(20) -0.4*cosd(20) -0.4*sind(20) 0.4*cosd(20) 0 0 0 0 0 0 0 0;
0 0 0 -1 0 0 0 1 0 0 0 0;
0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 0 0];
N3 = [mass_body1*Acceleration_G1x;
mass_body1*Acceleration_G1y+mass_body1*9.81;
mass_body1*radius_body1^2*alpha_1;
mass_body2*Acceleration_G2x;
mass_body2*Acceleration_G2y+mass_body2*9.81;
(1/12)*mass_body2*radius_body2^2*alpha_2;
mass_body3*Acceleration_G3x;
mass_body3*Acceleration_G3y+mass_body3*9.81;
(1/12)*mass_body3*radius_body3^2*alpha_3;
mass_body4*Acceleration_G4x;
mass_body4*Acceleration_G4y+mass_body4*9.81;
(1/12)*mass_body4*BD^2*alpha_4];
X = M3/N3
It says that there is an error using "/" and that matrix dimensions must agree. I dont know exactly what this means, and can’t find where the issue is. The error is in the line "X = M3/N3"% matrix calculation
M3 = [0 0 0 0 -1 0 0 0 0 0 1 0;
0 0 0 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 -0.05 1;
1 0 0 0 0 0 0 0 -1 0 -1 0;
0 -1 0 0 0 0 0 0 0 -1 0 0;
-0.15 0 0 0 0 0 0 0 -0.15 0 0.05 0;
-1 0 1 0 0 0 0 0 0 0 0 0;
0 1 0 1 0 0 0 0 0 0 0 0;
-0.4*sind(20) -0.4*cosd(20) -0.4*sind(20) 0.4*cosd(20) 0 0 0 0 0 0 0 0;
0 0 0 -1 0 0 0 1 0 0 0 0;
0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 0 0];
N3 = [mass_body1*Acceleration_G1x;
mass_body1*Acceleration_G1y+mass_body1*9.81;
mass_body1*radius_body1^2*alpha_1;
mass_body2*Acceleration_G2x;
mass_body2*Acceleration_G2y+mass_body2*9.81;
(1/12)*mass_body2*radius_body2^2*alpha_2;
mass_body3*Acceleration_G3x;
mass_body3*Acceleration_G3y+mass_body3*9.81;
(1/12)*mass_body3*radius_body3^2*alpha_3;
mass_body4*Acceleration_G4x;
mass_body4*Acceleration_G4y+mass_body4*9.81;
(1/12)*mass_body4*BD^2*alpha_4];
X = M3/N3
It says that there is an error using "/" and that matrix dimensions must agree. I dont know exactly what this means, and can’t find where the issue is. The error is in the line "X = M3/N3" % matrix calculation
M3 = [0 0 0 0 -1 0 0 0 0 0 1 0;
0 0 0 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 -0.05 1;
1 0 0 0 0 0 0 0 -1 0 -1 0;
0 -1 0 0 0 0 0 0 0 -1 0 0;
-0.15 0 0 0 0 0 0 0 -0.15 0 0.05 0;
-1 0 1 0 0 0 0 0 0 0 0 0;
0 1 0 1 0 0 0 0 0 0 0 0;
-0.4*sind(20) -0.4*cosd(20) -0.4*sind(20) 0.4*cosd(20) 0 0 0 0 0 0 0 0;
0 0 0 -1 0 0 0 1 0 0 0 0;
0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 0 0];
N3 = [mass_body1*Acceleration_G1x;
mass_body1*Acceleration_G1y+mass_body1*9.81;
mass_body1*radius_body1^2*alpha_1;
mass_body2*Acceleration_G2x;
mass_body2*Acceleration_G2y+mass_body2*9.81;
(1/12)*mass_body2*radius_body2^2*alpha_2;
mass_body3*Acceleration_G3x;
mass_body3*Acceleration_G3y+mass_body3*9.81;
(1/12)*mass_body3*radius_body3^2*alpha_3;
mass_body4*Acceleration_G4x;
mass_body4*Acceleration_G4y+mass_body4*9.81;
(1/12)*mass_body4*BD^2*alpha_4];
X = M3/N3
It says that there is an error using "/" and that matrix dimensions must agree. I dont know exactly what this means, and can’t find where the issue is. The error is in the line "X = M3/N3" matrix MATLAB Answers — New Questions
Simulink Discrete Filter Sample Time
Hello everybody I’m new here and new to simulink.
I have a problem
The Sample Time was "canceld" for the discrete Filter in the update 2023b.
At least the easy Set Up trough the Block Parameter, but I need it to initiated for the Task In Simu Link Fundamentals at step 4.5.
Does anyone know what i can do know? that would made my day.
Thank you
Best Regards
JanHello everybody I’m new here and new to simulink.
I have a problem
The Sample Time was "canceld" for the discrete Filter in the update 2023b.
At least the easy Set Up trough the Block Parameter, but I need it to initiated for the Task In Simu Link Fundamentals at step 4.5.
Does anyone know what i can do know? that would made my day.
Thank you
Best Regards
Jan Hello everybody I’m new here and new to simulink.
I have a problem
The Sample Time was "canceld" for the discrete Filter in the update 2023b.
At least the easy Set Up trough the Block Parameter, but I need it to initiated for the Task In Simu Link Fundamentals at step 4.5.
Does anyone know what i can do know? that would made my day.
Thank you
Best Regards
Jan #simulink, #fundamentals MATLAB Answers — New Questions
Ellipsoid Mask based on user input of dimension and euler angle
Actually I am trying to generate a 3d ellipsoid mask based on the user input of semi axes and euler angles. But in my code to do this I am calculating the distance of each pixel from the centre of the ellipse and then based on the ellipse equation pixels falling inside this ellipse are assigned true values. But the problem is that this operation is very tedious as I am scanning each and every pixel.
Any other way to do this which reduces the time complexity of this problem.
function y = mask_3D(a_axis, b_axis, c_axis, psi1, psi2, phi)
if a > b
diameter = 2 * a;
else
diameter = 2 * b;
end
if 2 * c > diameter
diameter = 2 * c;
end
if mod(diameter, round(diameter)) ~= 0
diameter = ceil(diameter);
end
radius = diameter / 2;
if mod(radius, round(radius)) ~= 0
diameter = diameter + 1;
radius = diameter / 2;
end
dist = 2 * ones(diameter + 1, diameter + 1, diameter + 1);
center = 1 + radius;
% Calculate the rotation matrix for the ellipse based on the Euler angles
rotation_matrix = zeros(3);
rotation_matrix(1, 1) = cos(psi1) * cos(psi2) – sin(psi1) * sin(psi2) * cos(phi);
rotation_matrix(2, 1) = -cos(psi1) * sin(psi2) – sin(psi1) * cos(psi2) * cos(phi);
rotation_matrix(3, 1) = sin(psi1) * sin(phi);
rotation_matrix(1, 2) = sin(psi1) * cos(psi2) + cos(psi1) * sin(psi2) * cos(phi);
rotation_matrix(2, 2) = -sin(psi1) * sin(psi2) + cos(psi1) * cos(psi2) * cos(phi);
rotation_matrix(3, 2) = -cos(psi1) * sin(phi);
rotation_matrix(1, 3) = sin(psi2) * sin(phi);
rotation_matrix(2, 3) = cos(psi2) * sin(phi);
rotation_matrix(3, 3) = cos(phi);
k = center – 1;
i_start = 1; i_end = diameter + 1;
j_start = 1; j_end = diameter + 1;
while k < diameter + 1
k = k + 1;
% Loop over all the pixels in the first plane to find
% the pixels belonging to the ellipse
for i = i_start:i_end
for j = j_start:j_end
a1 = [i – center, j – center, k – center];
a2 = [a^2, b^2, c^2];
c1 = a1 * rotation_matrix;
c2 = c1.^2 ./ a2;
dist(i, j, k) = sum(c2);
end
end
if sum(sum(dist(:,:,k) <= 1)) == 0
k = diameter + 1;
end
if k ~= center && k ~= diameter + 1
d = dist(:,:,k – 1) <= 1;
e = dist(:,:,k) <= 1;
d1 = diff(sum(d, 1) ~= 0);
dmin = find(d1 == 1);
dmax = find(d1 == -1);
if size(dmin, 2) > 1
dmin = dmin(1);
dmax = dmax(2);
end
e1 = diff(sum(e, 1) ~= 0);
emin = find(e1 == 1);
emax = find(e1 == -1);
if size(emin, 2) > 1
emin = emin(1);
emax = emax(2);
end
if dmin – emin < 0
j_start = emin – 1;
j_end = j_start + 3 + (dmax – dmin);
if j_end > diameter + 1
j_end = diameter + 1;
end
end
if dmax – emax > 0
j_end = emax + 1;
j_start = j_end – 3 – (dmax – dmin);
if j_start < 1
j_start = 1;
end
end
d1 = diff(sum(d, 2) ~= 0);
dmin = find(d1 == 1);
dmax = find(d1 == -1);
if size(dmin, 1) > 1
dmin = dmin(1);
dmax = dmax(2);
end
e1 = diff(sum(e, 2) ~= 0);
emin = find(e1 == 1);
emax = find(e1 == -1);
if size(emin, 1) > 1
emin = emin(1);
emax = emax(2);
end
if dmin – emin < 0
i_start = emin – 1;
i_end = i_start + 3 + (dmax – dmin);
if i_end > diameter + 1
i_end = diameter + 1;
end
end
if dmax – emax > 0
i_end = emax + 1;
i_start = i_end – 3 – (dmax – dmin);
if i_start < 1
i_start = 1;
end
end
end
end
% Generate whole ellipse
y = dist <= 1;
x = y(1:diameter + 1, 1:diameter + 1, center + 1:diameter + 1);
x1 = zeros(diameter + 1, diameter + 1, center – 1);
for i = 1:size(x, 3)
x1(:,:,size(x, 3) – i + 1) = flipud(fliplr(x(:,:,i)));
end
y(1:diameter + 1, 1:diameter + 1, 1:center – 1) = x1;
endActually I am trying to generate a 3d ellipsoid mask based on the user input of semi axes and euler angles. But in my code to do this I am calculating the distance of each pixel from the centre of the ellipse and then based on the ellipse equation pixels falling inside this ellipse are assigned true values. But the problem is that this operation is very tedious as I am scanning each and every pixel.
Any other way to do this which reduces the time complexity of this problem.
function y = mask_3D(a_axis, b_axis, c_axis, psi1, psi2, phi)
if a > b
diameter = 2 * a;
else
diameter = 2 * b;
end
if 2 * c > diameter
diameter = 2 * c;
end
if mod(diameter, round(diameter)) ~= 0
diameter = ceil(diameter);
end
radius = diameter / 2;
if mod(radius, round(radius)) ~= 0
diameter = diameter + 1;
radius = diameter / 2;
end
dist = 2 * ones(diameter + 1, diameter + 1, diameter + 1);
center = 1 + radius;
% Calculate the rotation matrix for the ellipse based on the Euler angles
rotation_matrix = zeros(3);
rotation_matrix(1, 1) = cos(psi1) * cos(psi2) – sin(psi1) * sin(psi2) * cos(phi);
rotation_matrix(2, 1) = -cos(psi1) * sin(psi2) – sin(psi1) * cos(psi2) * cos(phi);
rotation_matrix(3, 1) = sin(psi1) * sin(phi);
rotation_matrix(1, 2) = sin(psi1) * cos(psi2) + cos(psi1) * sin(psi2) * cos(phi);
rotation_matrix(2, 2) = -sin(psi1) * sin(psi2) + cos(psi1) * cos(psi2) * cos(phi);
rotation_matrix(3, 2) = -cos(psi1) * sin(phi);
rotation_matrix(1, 3) = sin(psi2) * sin(phi);
rotation_matrix(2, 3) = cos(psi2) * sin(phi);
rotation_matrix(3, 3) = cos(phi);
k = center – 1;
i_start = 1; i_end = diameter + 1;
j_start = 1; j_end = diameter + 1;
while k < diameter + 1
k = k + 1;
% Loop over all the pixels in the first plane to find
% the pixels belonging to the ellipse
for i = i_start:i_end
for j = j_start:j_end
a1 = [i – center, j – center, k – center];
a2 = [a^2, b^2, c^2];
c1 = a1 * rotation_matrix;
c2 = c1.^2 ./ a2;
dist(i, j, k) = sum(c2);
end
end
if sum(sum(dist(:,:,k) <= 1)) == 0
k = diameter + 1;
end
if k ~= center && k ~= diameter + 1
d = dist(:,:,k – 1) <= 1;
e = dist(:,:,k) <= 1;
d1 = diff(sum(d, 1) ~= 0);
dmin = find(d1 == 1);
dmax = find(d1 == -1);
if size(dmin, 2) > 1
dmin = dmin(1);
dmax = dmax(2);
end
e1 = diff(sum(e, 1) ~= 0);
emin = find(e1 == 1);
emax = find(e1 == -1);
if size(emin, 2) > 1
emin = emin(1);
emax = emax(2);
end
if dmin – emin < 0
j_start = emin – 1;
j_end = j_start + 3 + (dmax – dmin);
if j_end > diameter + 1
j_end = diameter + 1;
end
end
if dmax – emax > 0
j_end = emax + 1;
j_start = j_end – 3 – (dmax – dmin);
if j_start < 1
j_start = 1;
end
end
d1 = diff(sum(d, 2) ~= 0);
dmin = find(d1 == 1);
dmax = find(d1 == -1);
if size(dmin, 1) > 1
dmin = dmin(1);
dmax = dmax(2);
end
e1 = diff(sum(e, 2) ~= 0);
emin = find(e1 == 1);
emax = find(e1 == -1);
if size(emin, 1) > 1
emin = emin(1);
emax = emax(2);
end
if dmin – emin < 0
i_start = emin – 1;
i_end = i_start + 3 + (dmax – dmin);
if i_end > diameter + 1
i_end = diameter + 1;
end
end
if dmax – emax > 0
i_end = emax + 1;
i_start = i_end – 3 – (dmax – dmin);
if i_start < 1
i_start = 1;
end
end
end
end
% Generate whole ellipse
y = dist <= 1;
x = y(1:diameter + 1, 1:diameter + 1, center + 1:diameter + 1);
x1 = zeros(diameter + 1, diameter + 1, center – 1);
for i = 1:size(x, 3)
x1(:,:,size(x, 3) – i + 1) = flipud(fliplr(x(:,:,i)));
end
y(1:diameter + 1, 1:diameter + 1, 1:center – 1) = x1;
end Actually I am trying to generate a 3d ellipsoid mask based on the user input of semi axes and euler angles. But in my code to do this I am calculating the distance of each pixel from the centre of the ellipse and then based on the ellipse equation pixels falling inside this ellipse are assigned true values. But the problem is that this operation is very tedious as I am scanning each and every pixel.
Any other way to do this which reduces the time complexity of this problem.
function y = mask_3D(a_axis, b_axis, c_axis, psi1, psi2, phi)
if a > b
diameter = 2 * a;
else
diameter = 2 * b;
end
if 2 * c > diameter
diameter = 2 * c;
end
if mod(diameter, round(diameter)) ~= 0
diameter = ceil(diameter);
end
radius = diameter / 2;
if mod(radius, round(radius)) ~= 0
diameter = diameter + 1;
radius = diameter / 2;
end
dist = 2 * ones(diameter + 1, diameter + 1, diameter + 1);
center = 1 + radius;
% Calculate the rotation matrix for the ellipse based on the Euler angles
rotation_matrix = zeros(3);
rotation_matrix(1, 1) = cos(psi1) * cos(psi2) – sin(psi1) * sin(psi2) * cos(phi);
rotation_matrix(2, 1) = -cos(psi1) * sin(psi2) – sin(psi1) * cos(psi2) * cos(phi);
rotation_matrix(3, 1) = sin(psi1) * sin(phi);
rotation_matrix(1, 2) = sin(psi1) * cos(psi2) + cos(psi1) * sin(psi2) * cos(phi);
rotation_matrix(2, 2) = -sin(psi1) * sin(psi2) + cos(psi1) * cos(psi2) * cos(phi);
rotation_matrix(3, 2) = -cos(psi1) * sin(phi);
rotation_matrix(1, 3) = sin(psi2) * sin(phi);
rotation_matrix(2, 3) = cos(psi2) * sin(phi);
rotation_matrix(3, 3) = cos(phi);
k = center – 1;
i_start = 1; i_end = diameter + 1;
j_start = 1; j_end = diameter + 1;
while k < diameter + 1
k = k + 1;
% Loop over all the pixels in the first plane to find
% the pixels belonging to the ellipse
for i = i_start:i_end
for j = j_start:j_end
a1 = [i – center, j – center, k – center];
a2 = [a^2, b^2, c^2];
c1 = a1 * rotation_matrix;
c2 = c1.^2 ./ a2;
dist(i, j, k) = sum(c2);
end
end
if sum(sum(dist(:,:,k) <= 1)) == 0
k = diameter + 1;
end
if k ~= center && k ~= diameter + 1
d = dist(:,:,k – 1) <= 1;
e = dist(:,:,k) <= 1;
d1 = diff(sum(d, 1) ~= 0);
dmin = find(d1 == 1);
dmax = find(d1 == -1);
if size(dmin, 2) > 1
dmin = dmin(1);
dmax = dmax(2);
end
e1 = diff(sum(e, 1) ~= 0);
emin = find(e1 == 1);
emax = find(e1 == -1);
if size(emin, 2) > 1
emin = emin(1);
emax = emax(2);
end
if dmin – emin < 0
j_start = emin – 1;
j_end = j_start + 3 + (dmax – dmin);
if j_end > diameter + 1
j_end = diameter + 1;
end
end
if dmax – emax > 0
j_end = emax + 1;
j_start = j_end – 3 – (dmax – dmin);
if j_start < 1
j_start = 1;
end
end
d1 = diff(sum(d, 2) ~= 0);
dmin = find(d1 == 1);
dmax = find(d1 == -1);
if size(dmin, 1) > 1
dmin = dmin(1);
dmax = dmax(2);
end
e1 = diff(sum(e, 2) ~= 0);
emin = find(e1 == 1);
emax = find(e1 == -1);
if size(emin, 1) > 1
emin = emin(1);
emax = emax(2);
end
if dmin – emin < 0
i_start = emin – 1;
i_end = i_start + 3 + (dmax – dmin);
if i_end > diameter + 1
i_end = diameter + 1;
end
end
if dmax – emax > 0
i_end = emax + 1;
i_start = i_end – 3 – (dmax – dmin);
if i_start < 1
i_start = 1;
end
end
end
end
% Generate whole ellipse
y = dist <= 1;
x = y(1:diameter + 1, 1:diameter + 1, center + 1:diameter + 1);
x1 = zeros(diameter + 1, diameter + 1, center – 1);
for i = 1:size(x, 3)
x1(:,:,size(x, 3) – i + 1) = flipud(fliplr(x(:,:,i)));
end
y(1:diameter + 1, 1:diameter + 1, 1:center – 1) = x1;
end image processing, mathematics, matrix array, optimization, binary MATLAB Answers — New Questions
Estimation of particle size in the image
Hi,
I am trying to estimate size of the particle in the attached image. As this image has both the particles and other shapes, hence, it is bit difficult to estimate the size of the particle alone. Could someone help with this?Hi,
I am trying to estimate size of the particle in the attached image. As this image has both the particles and other shapes, hence, it is bit difficult to estimate the size of the particle alone. Could someone help with this? Hi,
I am trying to estimate size of the particle in the attached image. As this image has both the particles and other shapes, hence, it is bit difficult to estimate the size of the particle alone. Could someone help with this? image processing, image segmentation, image thresold, binary image, particle size, image analysis MATLAB Answers — New Questions
Error in Hierarchical Risk Parity Portfolio
i followed code provided on MATLAB help section under finance/create hierarchical risk parity portfolio and I get this error ‘Unrecognized function or variable ‘getLeafNodesInGroup’. PLease advise on what can solve thisi followed code provided on MATLAB help section under finance/create hierarchical risk parity portfolio and I get this error ‘Unrecognized function or variable ‘getLeafNodesInGroup’. PLease advise on what can solve this i followed code provided on MATLAB help section under finance/create hierarchical risk parity portfolio and I get this error ‘Unrecognized function or variable ‘getLeafNodesInGroup’. PLease advise on what can solve this getleafnodesingroup, hierarchical risk parity MATLAB Answers — New Questions
How to change frequency range doubling of Complex-valued Chirp Signal Spectrogram to match the Real-Valued Chirp Spectrogram
When real-valued linear chirp is plotted in spectrogram, the frequency range is limited to the Nyquist rate frequency range.
However, when complex-valued linar chirp with the same parameters is plotted, the frequency range of the spectrogram doubles. Is there an option to limit the frequeny range to the Nyquist rate?
%%%% Sample Code %%%%
Fs=2E3; %sampling rate
f0=0; %initial frequency offset = 0
f1=0.5E3; %LFM sweeping frequency
t1=0.5;
t=0:1/Fs:t1;
%
%Real Valued Chirp
%
yr=chirp(t,f0,t1,f1,’real’);
figure
spectrogram(yr,[],256,512,Fs,’yaxis’);
title(‘UP Chirp-Real in Time-Freq ‘)
%
%Complex Valued Chirp
%
yc=chirp(t,f0,t1,f1,’complex’);
figure
spectrogram(yc,[],256,512,Fs,’yaxis’);
title(‘UP Chirp-Complex in Time-Freq ‘)When real-valued linear chirp is plotted in spectrogram, the frequency range is limited to the Nyquist rate frequency range.
However, when complex-valued linar chirp with the same parameters is plotted, the frequency range of the spectrogram doubles. Is there an option to limit the frequeny range to the Nyquist rate?
%%%% Sample Code %%%%
Fs=2E3; %sampling rate
f0=0; %initial frequency offset = 0
f1=0.5E3; %LFM sweeping frequency
t1=0.5;
t=0:1/Fs:t1;
%
%Real Valued Chirp
%
yr=chirp(t,f0,t1,f1,’real’);
figure
spectrogram(yr,[],256,512,Fs,’yaxis’);
title(‘UP Chirp-Real in Time-Freq ‘)
%
%Complex Valued Chirp
%
yc=chirp(t,f0,t1,f1,’complex’);
figure
spectrogram(yc,[],256,512,Fs,’yaxis’);
title(‘UP Chirp-Complex in Time-Freq ‘) When real-valued linear chirp is plotted in spectrogram, the frequency range is limited to the Nyquist rate frequency range.
However, when complex-valued linar chirp with the same parameters is plotted, the frequency range of the spectrogram doubles. Is there an option to limit the frequeny range to the Nyquist rate?
%%%% Sample Code %%%%
Fs=2E3; %sampling rate
f0=0; %initial frequency offset = 0
f1=0.5E3; %LFM sweeping frequency
t1=0.5;
t=0:1/Fs:t1;
%
%Real Valued Chirp
%
yr=chirp(t,f0,t1,f1,’real’);
figure
spectrogram(yr,[],256,512,Fs,’yaxis’);
title(‘UP Chirp-Real in Time-Freq ‘)
%
%Complex Valued Chirp
%
yc=chirp(t,f0,t1,f1,’complex’);
figure
spectrogram(yc,[],256,512,Fs,’yaxis’);
title(‘UP Chirp-Complex in Time-Freq ‘) chirp spread spectrum, matlab, spectrogram MATLAB Answers — New Questions
How to fix conjugated chirp signal frequency shift in spectrogram
When a complex-valued linear chirp signal is converted to its conjugate, the frequency shifts to the maximum sampling rate beyond the Nyqust rate. This does not happen in real-valued linear chirp. Is there an option to limit the frequency shift?
Fs=2E3;
f0=0;
f1=0.5E3;
t1=0.5;
t=0:1/Fs:t1;
yc=chirp(t,f0,t1,f1,’complex’);
figure
spectrogram(yc,[],256,512,Fs,’yaxis’);
title(‘UP Chirp-Complex in Time-Freq ‘)
%Plot Conjugate chirp
conj_yc=conj(yc);
figure
spectrogram(conj_yc,[],256,512,Fs,’yaxis’);
title(‘Conjugate-UP Chirp-Complex in Time-Freq ‘)When a complex-valued linear chirp signal is converted to its conjugate, the frequency shifts to the maximum sampling rate beyond the Nyqust rate. This does not happen in real-valued linear chirp. Is there an option to limit the frequency shift?
Fs=2E3;
f0=0;
f1=0.5E3;
t1=0.5;
t=0:1/Fs:t1;
yc=chirp(t,f0,t1,f1,’complex’);
figure
spectrogram(yc,[],256,512,Fs,’yaxis’);
title(‘UP Chirp-Complex in Time-Freq ‘)
%Plot Conjugate chirp
conj_yc=conj(yc);
figure
spectrogram(conj_yc,[],256,512,Fs,’yaxis’);
title(‘Conjugate-UP Chirp-Complex in Time-Freq ‘) When a complex-valued linear chirp signal is converted to its conjugate, the frequency shifts to the maximum sampling rate beyond the Nyqust rate. This does not happen in real-valued linear chirp. Is there an option to limit the frequency shift?
Fs=2E3;
f0=0;
f1=0.5E3;
t1=0.5;
t=0:1/Fs:t1;
yc=chirp(t,f0,t1,f1,’complex’);
figure
spectrogram(yc,[],256,512,Fs,’yaxis’);
title(‘UP Chirp-Complex in Time-Freq ‘)
%Plot Conjugate chirp
conj_yc=conj(yc);
figure
spectrogram(conj_yc,[],256,512,Fs,’yaxis’);
title(‘Conjugate-UP Chirp-Complex in Time-Freq ‘) chirp, lfm, matlab, spectrogram MATLAB Answers — New Questions
License manager error -15
I am using AppsAnywhere to launch Matlab through my University system. It gives me License manager error -15.
Unfortunatley, I removed the directory where Matlab was prevsiouly installed. I don’t know what to do.I am using AppsAnywhere to launch Matlab through my University system. It gives me License manager error -15.
Unfortunatley, I removed the directory where Matlab was prevsiouly installed. I don’t know what to do. I am using AppsAnywhere to launch Matlab through my University system. It gives me License manager error -15.
Unfortunatley, I removed the directory where Matlab was prevsiouly installed. I don’t know what to do. license manager error -15 MATLAB Answers — New Questions
I need to code a pipe network and solve for flow rates and ideal pump head. I have the basis of a code using fsolve with my equations and unkowns, but keep exceeding iteration
function Mary_H_Kennedy_Fluids_Project
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pipe Flow Project
% Mary Helen Kennedy
% ME 3834 — Fluid Mechanics
% Spring 2024
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Q1 = 4.456; %ft3/s
v1 = 22.69; %ft/s
L = 100; %ft
D = 0.5; %ft
e = 0.00085; %ft
rho = 62; %lbm/ft^3
f = 0.0023; %Initial guess
mu = 2.05*10^-5;
Re = (rho*v1*D)/mu;
A = 0.196;
% Define the function
fun = @(F) [
(F(2)/(rho*9.81)) – (F(1)) + ((v1^2)/(2*9.81)*(f*(L/D)-1)); % Equation for Pipe 1
F(2) – (rho*9.81)*(f*(L/D)*(F(5)^2)/(2*9.81*A^2)); % Equation for Pipe 2
F(2) – (rho*9.81)*(f*(L/D)*(F(5)^2)/(2*9.81*A^2)); % Equation for Pipe 3
(F(2) – F(4)) – (rho*9.81)*(f*(L/D)*(F(6)^2)/(2*9.81*A^2)); % Equation for Pipe 4
F(4) – (rho*9.81)*(f*(L/D)*(F(7)^2)/(2*9.81*A^2)); % Equation for Pipe 5
F(4) – (rho*9.81)*(f*(L/D)*(F(8)^2)/(2*9.81*A^2)); % Equation for Pipe 6
F(5) + F(5) + F(6) – Q1; % Node A
F(6) – F(7) – F(8); % Node B
];
% Initial guess for unknowns
x0 = [2000, 500, 0.0023, 400, 24, 25, 26, 27];
% Call fsolve to solve the system of equations
options = optimoptions(‘fsolve’,’MaxFunctionEvaluations’,10000); % Adjust the maximum number of function evaluations
% Call fsolve with options
F = fsolve(fun, x0, options);
% Unknowns from fsolve
hl = F(1);
Pa = F(2);
f = F(3);
Pb = F(4);
Q3 = F(5);
Q4 = F(6);
Q5 = F(7);
Q6 = F(8);
endfunction Mary_H_Kennedy_Fluids_Project
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pipe Flow Project
% Mary Helen Kennedy
% ME 3834 — Fluid Mechanics
% Spring 2024
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Q1 = 4.456; %ft3/s
v1 = 22.69; %ft/s
L = 100; %ft
D = 0.5; %ft
e = 0.00085; %ft
rho = 62; %lbm/ft^3
f = 0.0023; %Initial guess
mu = 2.05*10^-5;
Re = (rho*v1*D)/mu;
A = 0.196;
% Define the function
fun = @(F) [
(F(2)/(rho*9.81)) – (F(1)) + ((v1^2)/(2*9.81)*(f*(L/D)-1)); % Equation for Pipe 1
F(2) – (rho*9.81)*(f*(L/D)*(F(5)^2)/(2*9.81*A^2)); % Equation for Pipe 2
F(2) – (rho*9.81)*(f*(L/D)*(F(5)^2)/(2*9.81*A^2)); % Equation for Pipe 3
(F(2) – F(4)) – (rho*9.81)*(f*(L/D)*(F(6)^2)/(2*9.81*A^2)); % Equation for Pipe 4
F(4) – (rho*9.81)*(f*(L/D)*(F(7)^2)/(2*9.81*A^2)); % Equation for Pipe 5
F(4) – (rho*9.81)*(f*(L/D)*(F(8)^2)/(2*9.81*A^2)); % Equation for Pipe 6
F(5) + F(5) + F(6) – Q1; % Node A
F(6) – F(7) – F(8); % Node B
];
% Initial guess for unknowns
x0 = [2000, 500, 0.0023, 400, 24, 25, 26, 27];
% Call fsolve to solve the system of equations
options = optimoptions(‘fsolve’,’MaxFunctionEvaluations’,10000); % Adjust the maximum number of function evaluations
% Call fsolve with options
F = fsolve(fun, x0, options);
% Unknowns from fsolve
hl = F(1);
Pa = F(2);
f = F(3);
Pb = F(4);
Q3 = F(5);
Q4 = F(6);
Q5 = F(7);
Q6 = F(8);
end function Mary_H_Kennedy_Fluids_Project
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pipe Flow Project
% Mary Helen Kennedy
% ME 3834 — Fluid Mechanics
% Spring 2024
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Q1 = 4.456; %ft3/s
v1 = 22.69; %ft/s
L = 100; %ft
D = 0.5; %ft
e = 0.00085; %ft
rho = 62; %lbm/ft^3
f = 0.0023; %Initial guess
mu = 2.05*10^-5;
Re = (rho*v1*D)/mu;
A = 0.196;
% Define the function
fun = @(F) [
(F(2)/(rho*9.81)) – (F(1)) + ((v1^2)/(2*9.81)*(f*(L/D)-1)); % Equation for Pipe 1
F(2) – (rho*9.81)*(f*(L/D)*(F(5)^2)/(2*9.81*A^2)); % Equation for Pipe 2
F(2) – (rho*9.81)*(f*(L/D)*(F(5)^2)/(2*9.81*A^2)); % Equation for Pipe 3
(F(2) – F(4)) – (rho*9.81)*(f*(L/D)*(F(6)^2)/(2*9.81*A^2)); % Equation for Pipe 4
F(4) – (rho*9.81)*(f*(L/D)*(F(7)^2)/(2*9.81*A^2)); % Equation for Pipe 5
F(4) – (rho*9.81)*(f*(L/D)*(F(8)^2)/(2*9.81*A^2)); % Equation for Pipe 6
F(5) + F(5) + F(6) – Q1; % Node A
F(6) – F(7) – F(8); % Node B
];
% Initial guess for unknowns
x0 = [2000, 500, 0.0023, 400, 24, 25, 26, 27];
% Call fsolve to solve the system of equations
options = optimoptions(‘fsolve’,’MaxFunctionEvaluations’,10000); % Adjust the maximum number of function evaluations
% Call fsolve with options
F = fsolve(fun, x0, options);
% Unknowns from fsolve
hl = F(1);
Pa = F(2);
f = F(3);
Pb = F(4);
Q3 = F(5);
Q4 = F(6);
Q5 = F(7);
Q6 = F(8);
end fsolve, fluids, help, iterations MATLAB Answers — New Questions
Find a smaller matrix within a larger matrix
I have two matrices with different sizes and I need to find the lower matrix inside the higher matrix.
Example
– Lower Matrix (Unique [1×7])
[ 2 3 4 5 6 7]
– Higher Matrix (Several results [1000×15])
[ 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] OK
[ 2 3 4 5 6 7 10 12 13 15 16 19 20 22 23] OK
[ 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17] NOK
. . .
If the 7 numbers from lower matrix matches inside some row from 15 numbers higher matrix, store the result from higher matrix.
It should analyze each row from higher matrix.I have two matrices with different sizes and I need to find the lower matrix inside the higher matrix.
Example
– Lower Matrix (Unique [1×7])
[ 2 3 4 5 6 7]
– Higher Matrix (Several results [1000×15])
[ 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] OK
[ 2 3 4 5 6 7 10 12 13 15 16 19 20 22 23] OK
[ 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17] NOK
. . .
If the 7 numbers from lower matrix matches inside some row from 15 numbers higher matrix, store the result from higher matrix.
It should analyze each row from higher matrix. I have two matrices with different sizes and I need to find the lower matrix inside the higher matrix.
Example
– Lower Matrix (Unique [1×7])
[ 2 3 4 5 6 7]
– Higher Matrix (Several results [1000×15])
[ 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] OK
[ 2 3 4 5 6 7 10 12 13 15 16 19 20 22 23] OK
[ 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17] NOK
. . .
If the 7 numbers from lower matrix matches inside some row from 15 numbers higher matrix, store the result from higher matrix.
It should analyze each row from higher matrix. contains, matrix array MATLAB Answers — New Questions
why is NaN not of ‘NaN type’ in Simulink?
Hi everyone,
Please, could anyone explain why the constant block NaN is not of type NaN?
Thank you in advance!
Best regards,
NicolasHi everyone,
Please, could anyone explain why the constant block NaN is not of type NaN?
Thank you in advance!
Best regards,
Nicolas Hi everyone,
Please, could anyone explain why the constant block NaN is not of type NaN?
Thank you in advance!
Best regards,
Nicolas simulink, nan MATLAB Answers — New Questions
How to use operations in for loop problems
For values of 1 to 60, create a for-loop that does the following. If the value is 1 to 20, have
the operation be number2, if the value is 21 to 40, have the operation be number, and if the
value is 41 to 60, have the operation be √number. Store all 60 results in 3 different variables
that start at 1. With the results, create a 3×20 matrix where the first row is the results of the
first operation, the second row being the results of the second operation, and the final row
being the results of the final operationFor values of 1 to 60, create a for-loop that does the following. If the value is 1 to 20, have
the operation be number2, if the value is 21 to 40, have the operation be number, and if the
value is 41 to 60, have the operation be √number. Store all 60 results in 3 different variables
that start at 1. With the results, create a 3×20 matrix where the first row is the results of the
first operation, the second row being the results of the second operation, and the final row
being the results of the final operation For values of 1 to 60, create a for-loop that does the following. If the value is 1 to 20, have
the operation be number2, if the value is 21 to 40, have the operation be number, and if the
value is 41 to 60, have the operation be √number. Store all 60 results in 3 different variables
that start at 1. With the results, create a 3×20 matrix where the first row is the results of the
first operation, the second row being the results of the second operation, and the final row
being the results of the final operation for loop, operations, matrix MATLAB Answers — New Questions
colorbar label along y-axis instead of x-axis
Hello! I would like the colorbar label to appear directly underneath the colorbar (right underneath the "220" in the figure below), horizontal along the x axis. However, when I specify this as follows, it aligns the label along the y axis.
Here is the relevant code:
contourf(lon,lat,tmp2, 25, ‘LineStyle’,’none’);
hold on
colormap(‘turbo’)
set(gca,’fontsize’,14);
ylabel(‘Latitude (circ)’)
xlabel(‘Longitude (circ)’)
h = colorbar;
xlabel(h,'(K)’);
hold off
——
can someone help me change the orientation of that ‘(K)’, and show me how to adjust my code in general so I can make this adjustments in other plots as well? Thanks.Hello! I would like the colorbar label to appear directly underneath the colorbar (right underneath the "220" in the figure below), horizontal along the x axis. However, when I specify this as follows, it aligns the label along the y axis.
Here is the relevant code:
contourf(lon,lat,tmp2, 25, ‘LineStyle’,’none’);
hold on
colormap(‘turbo’)
set(gca,’fontsize’,14);
ylabel(‘Latitude (circ)’)
xlabel(‘Longitude (circ)’)
h = colorbar;
xlabel(h,'(K)’);
hold off
——
can someone help me change the orientation of that ‘(K)’, and show me how to adjust my code in general so I can make this adjustments in other plots as well? Thanks. Hello! I would like the colorbar label to appear directly underneath the colorbar (right underneath the "220" in the figure below), horizontal along the x axis. However, when I specify this as follows, it aligns the label along the y axis.
Here is the relevant code:
contourf(lon,lat,tmp2, 25, ‘LineStyle’,’none’);
hold on
colormap(‘turbo’)
set(gca,’fontsize’,14);
ylabel(‘Latitude (circ)’)
xlabel(‘Longitude (circ)’)
h = colorbar;
xlabel(h,'(K)’);
hold off
——
can someone help me change the orientation of that ‘(K)’, and show me how to adjust my code in general so I can make this adjustments in other plots as well? Thanks. xlabel colorbar, colorbar orientation, colorbar, ylabel colorbar MATLAB Answers — New Questions
MATLAB Web App does not load when it comes to hosting
Hi,
I have truoble loading my web app on my web app homepage.
Other open-source web app example (mortgage calculator) does work well on the web app server,
but the one that I made on web app homepage does not finish loading, after I clicked on homepage.
Does anyone know some possible causes of this infinite loading error?
Thank you for reading.Hi,
I have truoble loading my web app on my web app homepage.
Other open-source web app example (mortgage calculator) does work well on the web app server,
but the one that I made on web app homepage does not finish loading, after I clicked on homepage.
Does anyone know some possible causes of this infinite loading error?
Thank you for reading. Hi,
I have truoble loading my web app on my web app homepage.
Other open-source web app example (mortgage calculator) does work well on the web app server,
but the one that I made on web app homepage does not finish loading, after I clicked on homepage.
Does anyone know some possible causes of this infinite loading error?
Thank you for reading. web app, web app load, web app host MATLAB Answers — New Questions
Can you load a WAVES VST plugin with Audio Toolbox?
I’m trying to load a VST3 plugin from WAVES using loadAudioPlugin() from MATLAB Audio Toolbox but I get the following error (in comments):
loadAudioPlugin(‘/Library/Audio/Plug-Ins/VST3/WaveShell1-VST3 14.17.vst3’)
% Unexpected unknown exception from MEX file..
% Error in hostmexif.newplugininstance
%
% Error in loadAudioPlugin
This seems to be due to Waves using WaveShell as a software gateway to the actual VST plugin — see https://www.waves.com/support/how-to-use-waves-plugins-when-using-custom-vst-folder
Anyone had any success loading a Waves VST3 plugin into MATLAB?I’m trying to load a VST3 plugin from WAVES using loadAudioPlugin() from MATLAB Audio Toolbox but I get the following error (in comments):
loadAudioPlugin(‘/Library/Audio/Plug-Ins/VST3/WaveShell1-VST3 14.17.vst3’)
% Unexpected unknown exception from MEX file..
% Error in hostmexif.newplugininstance
%
% Error in loadAudioPlugin
This seems to be due to Waves using WaveShell as a software gateway to the actual VST plugin — see https://www.waves.com/support/how-to-use-waves-plugins-when-using-custom-vst-folder
Anyone had any success loading a Waves VST3 plugin into MATLAB? I’m trying to load a VST3 plugin from WAVES using loadAudioPlugin() from MATLAB Audio Toolbox but I get the following error (in comments):
loadAudioPlugin(‘/Library/Audio/Plug-Ins/VST3/WaveShell1-VST3 14.17.vst3’)
% Unexpected unknown exception from MEX file..
% Error in hostmexif.newplugininstance
%
% Error in loadAudioPlugin
This seems to be due to Waves using WaveShell as a software gateway to the actual VST plugin — see https://www.waves.com/support/how-to-use-waves-plugins-when-using-custom-vst-folder
Anyone had any success loading a Waves VST3 plugin into MATLAB? waves, audio toolbox, vst plugin MATLAB Answers — New Questions
Find Eigenvalues of ODE45 Solution MATLAB
I have the following non-linear ODE:
I have the following ODE45 solution:
fun = @(t,X)odefun(X,K,C,M,F(t),resSize);
[t_ode,X_answer] = ode45(fun,tspan,X_0);
The input matrices are stiffness K(X), damping C, mass M, and force F. resSize is the total number of masses in the system.
I would like to find the system’s eigenvalues using either the Jacobian matrix, transfer function, or any other viable method.
I have tried using:
[vector,lambda,condition_number] = polyeig(K(X_answer),C,M);
This is tricky since my K matrix is a function handle of X. In other words, K=@(X). X represents a displacement vector of each mass in the system (x_1(t),x_2(t),…x_resSize(t)), where resSize is the total number of masses. My X_answer matrix is a double with dimensions of t_ode by resSize, where each row is the displacement vector of each mass in double form. Is there some way to substitute X_answer into my function handle for K so I can use polyeig()? If not, how would I go about finding my system’s transfer function or Jacobian matrix so that I can find it’s eigenvalues?I have the following non-linear ODE:
I have the following ODE45 solution:
fun = @(t,X)odefun(X,K,C,M,F(t),resSize);
[t_ode,X_answer] = ode45(fun,tspan,X_0);
The input matrices are stiffness K(X), damping C, mass M, and force F. resSize is the total number of masses in the system.
I would like to find the system’s eigenvalues using either the Jacobian matrix, transfer function, or any other viable method.
I have tried using:
[vector,lambda,condition_number] = polyeig(K(X_answer),C,M);
This is tricky since my K matrix is a function handle of X. In other words, K=@(X). X represents a displacement vector of each mass in the system (x_1(t),x_2(t),…x_resSize(t)), where resSize is the total number of masses. My X_answer matrix is a double with dimensions of t_ode by resSize, where each row is the displacement vector of each mass in double form. Is there some way to substitute X_answer into my function handle for K so I can use polyeig()? If not, how would I go about finding my system’s transfer function or Jacobian matrix so that I can find it’s eigenvalues? I have the following non-linear ODE:
I have the following ODE45 solution:
fun = @(t,X)odefun(X,K,C,M,F(t),resSize);
[t_ode,X_answer] = ode45(fun,tspan,X_0);
The input matrices are stiffness K(X), damping C, mass M, and force F. resSize is the total number of masses in the system.
I would like to find the system’s eigenvalues using either the Jacobian matrix, transfer function, or any other viable method.
I have tried using:
[vector,lambda,condition_number] = polyeig(K(X_answer),C,M);
This is tricky since my K matrix is a function handle of X. In other words, K=@(X). X represents a displacement vector of each mass in the system (x_1(t),x_2(t),…x_resSize(t)), where resSize is the total number of masses. My X_answer matrix is a double with dimensions of t_ode by resSize, where each row is the displacement vector of each mass in double form. Is there some way to substitute X_answer into my function handle for K so I can use polyeig()? If not, how would I go about finding my system’s transfer function or Jacobian matrix so that I can find it’s eigenvalues? function, ode45, transfer function, matlab MATLAB Answers — New Questions
ExperienceBufferLength in Reinforcement Learning Toolbox
Hello, everyone,
I found a problem with the ‘ExperienceBufferLength’ property in ‘rlDDPGAgentOptions’ when specifying options for rl agents.
Usually this property is set as 1e6 in the examples of the Help documentation, such as here.
In this example, every episode has 600 (60/0.1) steps. Does the agent start to train when the experience buffer is filled up with the experiences (S,A,R,S’). If so, it would take at least 1667 (1000000/600 ) episodes before the agent starts to improve.
So I want to know how to determine this value.Hello, everyone,
I found a problem with the ‘ExperienceBufferLength’ property in ‘rlDDPGAgentOptions’ when specifying options for rl agents.
Usually this property is set as 1e6 in the examples of the Help documentation, such as here.
In this example, every episode has 600 (60/0.1) steps. Does the agent start to train when the experience buffer is filled up with the experiences (S,A,R,S’). If so, it would take at least 1667 (1000000/600 ) episodes before the agent starts to improve.
So I want to know how to determine this value. Hello, everyone,
I found a problem with the ‘ExperienceBufferLength’ property in ‘rlDDPGAgentOptions’ when specifying options for rl agents.
Usually this property is set as 1e6 in the examples of the Help documentation, such as here.
In this example, every episode has 600 (60/0.1) steps. Does the agent start to train when the experience buffer is filled up with the experiences (S,A,R,S’). If so, it would take at least 1667 (1000000/600 ) episodes before the agent starts to improve.
So I want to know how to determine this value. reinforcement learning, ddpg, experiencebufferlength MATLAB Answers — New Questions
Error using fmincon and integral2: taking integral variables theta and p as an array while performing computation
I am minimizing q for whole range of p and theta; p has limit from 2pi to 20pi and theta from 0 to pi; to find the value of d, r_g,G_g. q is function of theta, p,d, r_g, G_g.
But while computation p and theta are behaving as an array. Because of this I am getting error. I tried using "ArrayValued", true. This is also not working. How to correct this. Here my part of code
[q] = optimizeParameters();% Call optimizeParameters to define the objective function q
options = optimset(‘PlotFcns’, @optimplotfval);% Set optimization options
d0 = [-0.5, 24, 3e6];
lb = [-1, 24, 2e6];
ub = [0, 32, 6e6];
[solution,fval] = fmincon(@(x)integral2(@(theta,p)q(theta,p,x(1),x(2),x(3)),pi/36,pi/6,2*pi,20*pi),d0,[],[],[],[],lb,ub,[],options); % minimize
function q = optimizeParameters()
Vs = 250;
k = @(p)p/Vs;
c = @(theta)Vs./sin(theta);
w5 = 0.001;
n = 3;
dl = -6;
d1 = @(d)dl + 2 * n * d – d;
q = @(theta, p, d, r_g, G_g) calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
end
function answer = calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
% printing the p and thetahere which is giving an array because of this error in further computation
theta
p
% rest of the code
endI am minimizing q for whole range of p and theta; p has limit from 2pi to 20pi and theta from 0 to pi; to find the value of d, r_g,G_g. q is function of theta, p,d, r_g, G_g.
But while computation p and theta are behaving as an array. Because of this I am getting error. I tried using "ArrayValued", true. This is also not working. How to correct this. Here my part of code
[q] = optimizeParameters();% Call optimizeParameters to define the objective function q
options = optimset(‘PlotFcns’, @optimplotfval);% Set optimization options
d0 = [-0.5, 24, 3e6];
lb = [-1, 24, 2e6];
ub = [0, 32, 6e6];
[solution,fval] = fmincon(@(x)integral2(@(theta,p)q(theta,p,x(1),x(2),x(3)),pi/36,pi/6,2*pi,20*pi),d0,[],[],[],[],lb,ub,[],options); % minimize
function q = optimizeParameters()
Vs = 250;
k = @(p)p/Vs;
c = @(theta)Vs./sin(theta);
w5 = 0.001;
n = 3;
dl = -6;
d1 = @(d)dl + 2 * n * d – d;
q = @(theta, p, d, r_g, G_g) calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
end
function answer = calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
% printing the p and thetahere which is giving an array because of this error in further computation
theta
p
% rest of the code
end I am minimizing q for whole range of p and theta; p has limit from 2pi to 20pi and theta from 0 to pi; to find the value of d, r_g,G_g. q is function of theta, p,d, r_g, G_g.
But while computation p and theta are behaving as an array. Because of this I am getting error. I tried using "ArrayValued", true. This is also not working. How to correct this. Here my part of code
[q] = optimizeParameters();% Call optimizeParameters to define the objective function q
options = optimset(‘PlotFcns’, @optimplotfval);% Set optimization options
d0 = [-0.5, 24, 3e6];
lb = [-1, 24, 2e6];
ub = [0, 32, 6e6];
[solution,fval] = fmincon(@(x)integral2(@(theta,p)q(theta,p,x(1),x(2),x(3)),pi/36,pi/6,2*pi,20*pi),d0,[],[],[],[],lb,ub,[],options); % minimize
function q = optimizeParameters()
Vs = 250;
k = @(p)p/Vs;
c = @(theta)Vs./sin(theta);
w5 = 0.001;
n = 3;
dl = -6;
d1 = @(d)dl + 2 * n * d – d;
q = @(theta, p, d, r_g, G_g) calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
end
function answer = calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
% printing the p and thetahere which is giving an array because of this error in further computation
theta
p
% rest of the code
end integral2, fmicon, arrayvalued MATLAB Answers — New Questions
constrainted regularization to solve ill conditioned problems?
I am trying to solve a matrix equation of the form Ax = b (solving for x with known A and b).
prior to trying regularisation I was using lsqlin (https://uk.mathworks.com/help/optim/ug/lsqlin.html) with the constraints lsqlin(C,d,[],[],[],[],lb,ub) where lb and ub are lower and upper bounds for the allowed values of my output vector. Some (but not all) of my vector values in x should not have negative values. My results are ill-conditioned. I was wondering if anyone is aware of any type of regularisation (e.g. Tikhonov) that has lb or ub constraints such that I can make some (but not all) of my values in x non-negative?
For context:
I have tried using Tikhonov regularisation (the example code given here: https://uk.mathworks.com/matlabcentral/fileexchange/130259-arls-automatically-regularized-least-squares?s_tid=prof_contriblnk – the response from 15 Mar 2024). The issue is that this code does not have any constraints.I am trying to solve a matrix equation of the form Ax = b (solving for x with known A and b).
prior to trying regularisation I was using lsqlin (https://uk.mathworks.com/help/optim/ug/lsqlin.html) with the constraints lsqlin(C,d,[],[],[],[],lb,ub) where lb and ub are lower and upper bounds for the allowed values of my output vector. Some (but not all) of my vector values in x should not have negative values. My results are ill-conditioned. I was wondering if anyone is aware of any type of regularisation (e.g. Tikhonov) that has lb or ub constraints such that I can make some (but not all) of my values in x non-negative?
For context:
I have tried using Tikhonov regularisation (the example code given here: https://uk.mathworks.com/matlabcentral/fileexchange/130259-arls-automatically-regularized-least-squares?s_tid=prof_contriblnk – the response from 15 Mar 2024). The issue is that this code does not have any constraints. I am trying to solve a matrix equation of the form Ax = b (solving for x with known A and b).
prior to trying regularisation I was using lsqlin (https://uk.mathworks.com/help/optim/ug/lsqlin.html) with the constraints lsqlin(C,d,[],[],[],[],lb,ub) where lb and ub are lower and upper bounds for the allowed values of my output vector. Some (but not all) of my vector values in x should not have negative values. My results are ill-conditioned. I was wondering if anyone is aware of any type of regularisation (e.g. Tikhonov) that has lb or ub constraints such that I can make some (but not all) of my values in x non-negative?
For context:
I have tried using Tikhonov regularisation (the example code given here: https://uk.mathworks.com/matlabcentral/fileexchange/130259-arls-automatically-regularized-least-squares?s_tid=prof_contriblnk – the response from 15 Mar 2024). The issue is that this code does not have any constraints. tikhonov, regularisation, ill-conditioned, ill conditioned, matrix equation, constraints, constrained equations MATLAB Answers — New Questions