Tag Archives: matlab
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
Raspberry Pi 5 Setup – MATLAB Support Package
I just acquired the new Raspberry Pi 5, and wanted to connect to it through MATLAB. I’m using MATLAB 2021b, and followed the steps in setting up the Support package page for Raspberry Pi hardware. However, when I am asked to select a board there is no option for the Raspberry Pi 5 model, which prompts to me to think that’s not yet supported. Is this the case?I just acquired the new Raspberry Pi 5, and wanted to connect to it through MATLAB. I’m using MATLAB 2021b, and followed the steps in setting up the Support package page for Raspberry Pi hardware. However, when I am asked to select a board there is no option for the Raspberry Pi 5 model, which prompts to me to think that’s not yet supported. Is this the case? I just acquired the new Raspberry Pi 5, and wanted to connect to it through MATLAB. I’m using MATLAB 2021b, and followed the steps in setting up the Support package page for Raspberry Pi hardware. However, when I am asked to select a board there is no option for the Raspberry Pi 5 model, which prompts to me to think that’s not yet supported. Is this the case? #pi5, #supportpackage MATLAB Answers — New Questions
Thermal conductivity varying with temperature shows error: Matrix is too large to convert to linear index.
I am solving a steady state thermal model and want to vary thermal conductivity as a function of temperature for materials present in the model.
I have used
kp = @(location,state) 0.3049+0.006197*state.u-(1.153*10^-5)*(state.u).^2+(1.034*10^-8)*(state.u).^3-(3.352*10^-12)*(state.u).^4; % as function for variable thermal conductivity.
thermalProperties(model,"ThermalConductivity",kp,…
"Face", FaceID); % specific faces are assigned variable thermal conductivity
While solving model slover throws following error:
Matrix is too large to convert to linear index.
Error in pde.DiscretizedPDEModel/checkSpatialCoefsForUDependence (line 73)
self.cu = any(isnan(femat.K(:)));
Error in pde.DiscretizedPDEModel (line 36)
obj = obj.checkSpatialCoefsForUDependence(u0,tdummy);
Error in pde.ThermalModel/solve (line 139)
femodel = pde.DiscretizedPDEModel(self,p,e,t,coefstruct,u0,constCoeffsBCs);
Error in thermal_model_vary_pore_OL_limit_2_phase_updated (line 152)
results = solve(model);
The whole code is too long and uses 4-5 function to run 🙁
I have tried reducing the function for variable thermal conductivity to just linear (removing non-linear dependence on themperature) but it shows the same error.
Thanks in advance!I am solving a steady state thermal model and want to vary thermal conductivity as a function of temperature for materials present in the model.
I have used
kp = @(location,state) 0.3049+0.006197*state.u-(1.153*10^-5)*(state.u).^2+(1.034*10^-8)*(state.u).^3-(3.352*10^-12)*(state.u).^4; % as function for variable thermal conductivity.
thermalProperties(model,"ThermalConductivity",kp,…
"Face", FaceID); % specific faces are assigned variable thermal conductivity
While solving model slover throws following error:
Matrix is too large to convert to linear index.
Error in pde.DiscretizedPDEModel/checkSpatialCoefsForUDependence (line 73)
self.cu = any(isnan(femat.K(:)));
Error in pde.DiscretizedPDEModel (line 36)
obj = obj.checkSpatialCoefsForUDependence(u0,tdummy);
Error in pde.ThermalModel/solve (line 139)
femodel = pde.DiscretizedPDEModel(self,p,e,t,coefstruct,u0,constCoeffsBCs);
Error in thermal_model_vary_pore_OL_limit_2_phase_updated (line 152)
results = solve(model);
The whole code is too long and uses 4-5 function to run 🙁
I have tried reducing the function for variable thermal conductivity to just linear (removing non-linear dependence on themperature) but it shows the same error.
Thanks in advance! I am solving a steady state thermal model and want to vary thermal conductivity as a function of temperature for materials present in the model.
I have used
kp = @(location,state) 0.3049+0.006197*state.u-(1.153*10^-5)*(state.u).^2+(1.034*10^-8)*(state.u).^3-(3.352*10^-12)*(state.u).^4; % as function for variable thermal conductivity.
thermalProperties(model,"ThermalConductivity",kp,…
"Face", FaceID); % specific faces are assigned variable thermal conductivity
While solving model slover throws following error:
Matrix is too large to convert to linear index.
Error in pde.DiscretizedPDEModel/checkSpatialCoefsForUDependence (line 73)
self.cu = any(isnan(femat.K(:)));
Error in pde.DiscretizedPDEModel (line 36)
obj = obj.checkSpatialCoefsForUDependence(u0,tdummy);
Error in pde.ThermalModel/solve (line 139)
femodel = pde.DiscretizedPDEModel(self,p,e,t,coefstruct,u0,constCoeffsBCs);
Error in thermal_model_vary_pore_OL_limit_2_phase_updated (line 152)
results = solve(model);
The whole code is too long and uses 4-5 function to run 🙁
I have tried reducing the function for variable thermal conductivity to just linear (removing non-linear dependence on themperature) but it shows the same error.
Thanks in advance! thermal model, variable thermal conductivity, pde, function, large matrices, fem MATLAB Answers — New Questions
How do I create and place a non-uniform heat flux (Gaussian) on a cylinder with a center hole?
I’m trying to add a non-uniform heat flux to my simple model of a cylinder with a center hole. I know I need to create a function that describes the heat flux (Gaussian) but not sure how to do that in the context of my model. I believe the function can be applied as a thermalBC to Face 2 as shown below.
T_initial = 20;
t_end = 100;
model=createpde(‘thermal’,’transient’);
geo = multicylcinder([.3,2],.2,’void’,[1,0]);
modelGeometry = geo;
pdegplot(model,’FaceLabels’,on);
thermalProperties(model,’ThermalConductivity’,4,’MassDensity’,210,’SpecificHeat’,73);
thermalIC(model,T_initial);
% Heat Flux Function
% ——————
% function Qflux = @nonUniformHeatFlux
% ???
% ???
% ???
% end
thermalBC(model,’Face’,1,’Temperature’,20);
thermalBC(model,’Face’,2,’HeatFlux’,@nonUniformHeatFlux)
generateMesh(model)
pdemesh(model)
tlist = 0:10:t_end
modelresults = solve(model, tlist)
endI’m trying to add a non-uniform heat flux to my simple model of a cylinder with a center hole. I know I need to create a function that describes the heat flux (Gaussian) but not sure how to do that in the context of my model. I believe the function can be applied as a thermalBC to Face 2 as shown below.
T_initial = 20;
t_end = 100;
model=createpde(‘thermal’,’transient’);
geo = multicylcinder([.3,2],.2,’void’,[1,0]);
modelGeometry = geo;
pdegplot(model,’FaceLabels’,on);
thermalProperties(model,’ThermalConductivity’,4,’MassDensity’,210,’SpecificHeat’,73);
thermalIC(model,T_initial);
% Heat Flux Function
% ——————
% function Qflux = @nonUniformHeatFlux
% ???
% ???
% ???
% end
thermalBC(model,’Face’,1,’Temperature’,20);
thermalBC(model,’Face’,2,’HeatFlux’,@nonUniformHeatFlux)
generateMesh(model)
pdemesh(model)
tlist = 0:10:t_end
modelresults = solve(model, tlist)
end I’m trying to add a non-uniform heat flux to my simple model of a cylinder with a center hole. I know I need to create a function that describes the heat flux (Gaussian) but not sure how to do that in the context of my model. I believe the function can be applied as a thermalBC to Face 2 as shown below.
T_initial = 20;
t_end = 100;
model=createpde(‘thermal’,’transient’);
geo = multicylcinder([.3,2],.2,’void’,[1,0]);
modelGeometry = geo;
pdegplot(model,’FaceLabels’,on);
thermalProperties(model,’ThermalConductivity’,4,’MassDensity’,210,’SpecificHeat’,73);
thermalIC(model,T_initial);
% Heat Flux Function
% ——————
% function Qflux = @nonUniformHeatFlux
% ???
% ???
% ???
% end
thermalBC(model,’Face’,1,’Temperature’,20);
thermalBC(model,’Face’,2,’HeatFlux’,@nonUniformHeatFlux)
generateMesh(model)
pdemesh(model)
tlist = 0:10:t_end
modelresults = solve(model, tlist)
end thermal analysis, nonuniform-heat flux MATLAB Answers — New Questions
How to use a variable from script in a function that is in another script
Hello, I am coding a 2nd order differential solver and need to call a variable from the main script into a function script as shown below. I have tried using global however I have read that it is not accepted practice. Also note x2 and x3 are stored in another script called solver.m. Thank you!
fx2x3.m:
function dv3dt = fx2x3 (x2,x3)
dv3dt = ((k3)/(m3))*(x2-x3); %numbers substituted immediately to reduce lines
endHello, I am coding a 2nd order differential solver and need to call a variable from the main script into a function script as shown below. I have tried using global however I have read that it is not accepted practice. Also note x2 and x3 are stored in another script called solver.m. Thank you!
fx2x3.m:
function dv3dt = fx2x3 (x2,x3)
dv3dt = ((k3)/(m3))*(x2-x3); %numbers substituted immediately to reduce lines
end Hello, I am coding a 2nd order differential solver and need to call a variable from the main script into a function script as shown below. I have tried using global however I have read that it is not accepted practice. Also note x2 and x3 are stored in another script called solver.m. Thank you!
fx2x3.m:
function dv3dt = fx2x3 (x2,x3)
dv3dt = ((k3)/(m3))*(x2-x3); %numbers substituted immediately to reduce lines
end matlab code MATLAB Answers — New Questions
Squeeze some part of a plot
Hi, I’d like to squeze the above part of my plot so that the part after the break is 40% of the total y-axis and the below part is 60%. Is it possible to do that? Thank you very much.Hi, I’d like to squeze the above part of my plot so that the part after the break is 40% of the total y-axis and the below part is 60%. Is it possible to do that? Thank you very much. Hi, I’d like to squeze the above part of my plot so that the part after the break is 40% of the total y-axis and the below part is 60%. Is it possible to do that? Thank you very much. plotting, unproportianate axis MATLAB Answers — New Questions
uifigure() laggy with multiple axes, figure() does not support scrollable components
I made an interface to display data from multiple measurement channels. It’s using a Grid Layout Manager, so the first column with fixed pixel width contains channel options, and the second column with "1x" width has axes displaying data. It is Y-scrollable so it can display many channels no matter the window size.
But it gets laggy and possibly unusable when displaying just 10 channels. But I actually found that displaying the same amount of channels in a figure() window is not laggy at all.
But figure() does not support Grid Layout Manager, nor scrollable uipanel…
nb_points = 50e3;
nb_linesperaxes = 1;
nb_axes = 15;
fig = figure("Name","figure()");
fig_ax = arrayfun(@(k)axes(fig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),…
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),…
fig_ax,’UniformOutput’,false);
linkaxes(fig_ax,’x’)
zoom(fig_ax(1),’xon’)
pan(fig_ax(2),’xon’)
uifig = uifigure("Name","uifigure()");
uifig_ax = arrayfun(@(k)axes(uifig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),…
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),…
uifig_ax,’UniformOutput’,false);
linkaxes(uifig_ax,’x’)
zoom(uifig_ax(1),’xon’)
pan(uifig_ax(2),’xon’)
The figure() window works wells, whereas the uifigure() window is laggy. Once compiled as app, it’s even unusable on some not-too-old computers.
Is there an alternative to Grid Layout Manager or scrollable Panel for figure() windows ?
Is there any way to prevent uifigure() window being this laggy ?I made an interface to display data from multiple measurement channels. It’s using a Grid Layout Manager, so the first column with fixed pixel width contains channel options, and the second column with "1x" width has axes displaying data. It is Y-scrollable so it can display many channels no matter the window size.
But it gets laggy and possibly unusable when displaying just 10 channels. But I actually found that displaying the same amount of channels in a figure() window is not laggy at all.
But figure() does not support Grid Layout Manager, nor scrollable uipanel…
nb_points = 50e3;
nb_linesperaxes = 1;
nb_axes = 15;
fig = figure("Name","figure()");
fig_ax = arrayfun(@(k)axes(fig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),…
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),…
fig_ax,’UniformOutput’,false);
linkaxes(fig_ax,’x’)
zoom(fig_ax(1),’xon’)
pan(fig_ax(2),’xon’)
uifig = uifigure("Name","uifigure()");
uifig_ax = arrayfun(@(k)axes(uifig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),…
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),…
uifig_ax,’UniformOutput’,false);
linkaxes(uifig_ax,’x’)
zoom(uifig_ax(1),’xon’)
pan(uifig_ax(2),’xon’)
The figure() window works wells, whereas the uifigure() window is laggy. Once compiled as app, it’s even unusable on some not-too-old computers.
Is there an alternative to Grid Layout Manager or scrollable Panel for figure() windows ?
Is there any way to prevent uifigure() window being this laggy ? I made an interface to display data from multiple measurement channels. It’s using a Grid Layout Manager, so the first column with fixed pixel width contains channel options, and the second column with "1x" width has axes displaying data. It is Y-scrollable so it can display many channels no matter the window size.
But it gets laggy and possibly unusable when displaying just 10 channels. But I actually found that displaying the same amount of channels in a figure() window is not laggy at all.
But figure() does not support Grid Layout Manager, nor scrollable uipanel…
nb_points = 50e3;
nb_linesperaxes = 1;
nb_axes = 15;
fig = figure("Name","figure()");
fig_ax = arrayfun(@(k)axes(fig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),…
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),…
fig_ax,’UniformOutput’,false);
linkaxes(fig_ax,’x’)
zoom(fig_ax(1),’xon’)
pan(fig_ax(2),’xon’)
uifig = uifigure("Name","uifigure()");
uifig_ax = arrayfun(@(k)axes(uifig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),…
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),…
uifig_ax,’UniformOutput’,false);
linkaxes(uifig_ax,’x’)
zoom(uifig_ax(1),’xon’)
pan(uifig_ax(2),’xon’)
The figure() window works wells, whereas the uifigure() window is laggy. Once compiled as app, it’s even unusable on some not-too-old computers.
Is there an alternative to Grid Layout Manager or scrollable Panel for figure() windows ?
Is there any way to prevent uifigure() window being this laggy ? figure, uifigure, performance, laggy, scrollable, grid layout manager MATLAB Answers — New Questions
MATLAB Coder: Why am I receiving Invalid MEX-file error when trying to load a TensorFlowLite model with loadTFLiteModel after upgrading to Update 1 of R2024a release?
I’m using MATLAB Coder and I upgrade to Update 1 of R2024a release. When I try to use the loadTFLiteModel API using the Deep Learning Toolbox Interface for TensorFlow Lite support package, I encounter a strange error (Invalid MEX-file).
What does this error message mean?I’m using MATLAB Coder and I upgrade to Update 1 of R2024a release. When I try to use the loadTFLiteModel API using the Deep Learning Toolbox Interface for TensorFlow Lite support package, I encounter a strange error (Invalid MEX-file).
What does this error message mean? I’m using MATLAB Coder and I upgrade to Update 1 of R2024a release. When I try to use the loadTFLiteModel API using the Deep Learning Toolbox Interface for TensorFlow Lite support package, I encounter a strange error (Invalid MEX-file).
What does this error message mean? neural network, deep learning, matlab coder, code generation, tensorflow, tensorflow-lite, coder-tips MATLAB Answers — New Questions