Category: Matlab
Category Archives: Matlab
Add-on Installation behind firewall
We have many computers without Internet access.
We have tried the solution on:
Using the Matlab Package Manager behind a firewall/proxy – MATLAB Answers – MATLAB Central (mathworks.com)
we make exception for :
acl mathworks dstdomain .mathworks.com
acl mathworks dstdomain .edgekey.net
acl mathworks dstdomain .akamaiedge.net
acl mathworks dstdomain .digicert.com
acl mathworks2 dst 151.139.87.115
acl mathworks2 dst 151.139.87.87
But I get timeouts in the logs
(Mai 23, 2024 10:15:42) java.util.concurrent.TimeoutException
There is a single address without Name Solution it will try to connect.
151.139.87.115 and.87
We make an exception also for this, but it still doesn’ work.
What can we do?We have many computers without Internet access.
We have tried the solution on:
Using the Matlab Package Manager behind a firewall/proxy – MATLAB Answers – MATLAB Central (mathworks.com)
we make exception for :
acl mathworks dstdomain .mathworks.com
acl mathworks dstdomain .edgekey.net
acl mathworks dstdomain .akamaiedge.net
acl mathworks dstdomain .digicert.com
acl mathworks2 dst 151.139.87.115
acl mathworks2 dst 151.139.87.87
But I get timeouts in the logs
(Mai 23, 2024 10:15:42) java.util.concurrent.TimeoutException
There is a single address without Name Solution it will try to connect.
151.139.87.115 and.87
We make an exception also for this, but it still doesn’ work.
What can we do? We have many computers without Internet access.
We have tried the solution on:
Using the Matlab Package Manager behind a firewall/proxy – MATLAB Answers – MATLAB Central (mathworks.com)
we make exception for :
acl mathworks dstdomain .mathworks.com
acl mathworks dstdomain .edgekey.net
acl mathworks dstdomain .akamaiedge.net
acl mathworks dstdomain .digicert.com
acl mathworks2 dst 151.139.87.115
acl mathworks2 dst 151.139.87.87
But I get timeouts in the logs
(Mai 23, 2024 10:15:42) java.util.concurrent.TimeoutException
There is a single address without Name Solution it will try to connect.
151.139.87.115 and.87
We make an exception also for this, but it still doesn’ work.
What can we do? installation, offline, proxy, firewall MATLAB Answers — New Questions
how to generate matlab code for handover in haterogeneous cellular network
how to generate matlab code for handover in haterogeneous cellular networkhow to generate matlab code for handover in haterogeneous cellular network how to generate matlab code for handover in haterogeneous cellular network handover MATLAB Answers — New Questions
a function with more one variable – in which these variables are derived from other functions
Hey
I am trying to have matlab run accept a function which I have tried to written up as followed.
I want it to calculate "average_density" which is depended on three variables. "porosity_average" and "density_s" which are functions and "z" which is a variable in "average_density" but is also present in the previously mentioned functions. I have gotten a lot different error messages, with must being in the like of either "too many input arguments" or too few – with some instances of it outwright just writing error and the line which the function is in.
I have a feeling this is an amateur error, but I have tried replicating the setup which are shown in other comment sections, though my attempts seemed to fail.
PS. I am not actual trying to make it calculate the average of the density, the newer functioner is already derived from the other density function.
Thank you in advance
porosity = @(z) phi_0 * exp(-z / L);
density_s = @(z) (rho_s_matrix *(1 – porosity(z)) + rho_w * porosity(z));
porosity_average = @(S_initial) (L * phi_0 / S_initial) * (1 – exp(-S_intial / L));
average_density_s = @(porosity_average, density_s,S_intial) density_s(z) * (1 – porosity_average(S_intial)) + rho_w * porosity_average(S);
S = S_initial;
iteration = 0;
max_iterations = 1000; % To prevent infinite loop
while true
iteration = iteration + 1;
average_density_s(density_s) = average_density_s(S, 1000);
W = ((rho_w * S)/average_density_s(z))-S;
S_new = S + W;
fprintf(‘Iteration %d: S = %.2f, W = %.2f, S_new = %.2fn’, iteration, S, W, S_new);
if abs(W) < epsilon
break;
end
S = S_new;
end
S_final = S;
endHey
I am trying to have matlab run accept a function which I have tried to written up as followed.
I want it to calculate "average_density" which is depended on three variables. "porosity_average" and "density_s" which are functions and "z" which is a variable in "average_density" but is also present in the previously mentioned functions. I have gotten a lot different error messages, with must being in the like of either "too many input arguments" or too few – with some instances of it outwright just writing error and the line which the function is in.
I have a feeling this is an amateur error, but I have tried replicating the setup which are shown in other comment sections, though my attempts seemed to fail.
PS. I am not actual trying to make it calculate the average of the density, the newer functioner is already derived from the other density function.
Thank you in advance
porosity = @(z) phi_0 * exp(-z / L);
density_s = @(z) (rho_s_matrix *(1 – porosity(z)) + rho_w * porosity(z));
porosity_average = @(S_initial) (L * phi_0 / S_initial) * (1 – exp(-S_intial / L));
average_density_s = @(porosity_average, density_s,S_intial) density_s(z) * (1 – porosity_average(S_intial)) + rho_w * porosity_average(S);
S = S_initial;
iteration = 0;
max_iterations = 1000; % To prevent infinite loop
while true
iteration = iteration + 1;
average_density_s(density_s) = average_density_s(S, 1000);
W = ((rho_w * S)/average_density_s(z))-S;
S_new = S + W;
fprintf(‘Iteration %d: S = %.2f, W = %.2f, S_new = %.2fn’, iteration, S, W, S_new);
if abs(W) < epsilon
break;
end
S = S_new;
end
S_final = S;
end Hey
I am trying to have matlab run accept a function which I have tried to written up as followed.
I want it to calculate "average_density" which is depended on three variables. "porosity_average" and "density_s" which are functions and "z" which is a variable in "average_density" but is also present in the previously mentioned functions. I have gotten a lot different error messages, with must being in the like of either "too many input arguments" or too few – with some instances of it outwright just writing error and the line which the function is in.
I have a feeling this is an amateur error, but I have tried replicating the setup which are shown in other comment sections, though my attempts seemed to fail.
PS. I am not actual trying to make it calculate the average of the density, the newer functioner is already derived from the other density function.
Thank you in advance
porosity = @(z) phi_0 * exp(-z / L);
density_s = @(z) (rho_s_matrix *(1 – porosity(z)) + rho_w * porosity(z));
porosity_average = @(S_initial) (L * phi_0 / S_initial) * (1 – exp(-S_intial / L));
average_density_s = @(porosity_average, density_s,S_intial) density_s(z) * (1 – porosity_average(S_intial)) + rho_w * porosity_average(S);
S = S_initial;
iteration = 0;
max_iterations = 1000; % To prevent infinite loop
while true
iteration = iteration + 1;
average_density_s(density_s) = average_density_s(S, 1000);
W = ((rho_w * S)/average_density_s(z))-S;
S_new = S + W;
fprintf(‘Iteration %d: S = %.2f, W = %.2f, S_new = %.2fn’, iteration, S, W, S_new);
if abs(W) < epsilon
break;
end
S = S_new;
end
S_final = S;
end too many input arguments or too few. functions MATLAB Answers — New Questions
How can I fix an index error in my code for training a semantic segmentation network?
I tweaked the existing semantic segmentation example so that I could use my own annotations and images. However, every time I run the code, I keep getting an error that an index of some sort is out of bounds (<=59 to be exact, see the screenshot attached). I traced the stack and found that the number of annotations was 59, while the number of images was 60. I was able to find that I had not annotated one of the images. After fixing this and reexporting the ground truth file, the index error was now <=60. I have attached my code and the groundTruth file I exported from the MATLAB imageLabeler tool. I was wondering if there is an index or list somewhere that I am missing.I tweaked the existing semantic segmentation example so that I could use my own annotations and images. However, every time I run the code, I keep getting an error that an index of some sort is out of bounds (<=59 to be exact, see the screenshot attached). I traced the stack and found that the number of annotations was 59, while the number of images was 60. I was able to find that I had not annotated one of the images. After fixing this and reexporting the ground truth file, the index error was now <=60. I have attached my code and the groundTruth file I exported from the MATLAB imageLabeler tool. I was wondering if there is an index or list somewhere that I am missing. I tweaked the existing semantic segmentation example so that I could use my own annotations and images. However, every time I run the code, I keep getting an error that an index of some sort is out of bounds (<=59 to be exact, see the screenshot attached). I traced the stack and found that the number of annotations was 59, while the number of images was 60. I was able to find that I had not annotated one of the images. After fixing this and reexporting the ground truth file, the index error was now <=60. I have attached my code and the groundTruth file I exported from the MATLAB imageLabeler tool. I was wondering if there is an index or list somewhere that I am missing. image-processing, deep learning MATLAB Answers — New Questions
Why do I get the error “Unable to load https://127.0.0.1:27182/dduxservice/control status: 501” during the setup of MATLAB Connector?
Why do I get the error "Unable to load https://127.0.0.1:27182/dduxservice/control status: 501" during the setup of MATLAB Connector?Why do I get the error "Unable to load https://127.0.0.1:27182/dduxservice/control status: 501" during the setup of MATLAB Connector? Why do I get the error "Unable to load https://127.0.0.1:27182/dduxservice/control status: 501" during the setup of MATLAB Connector? MATLAB Answers — New Questions
How do I perform a sin^2 or a cos^2 fit for my data?
I have the following x data and y data:
x = [0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180]
y = [880,1200,1900,2700,3300,3600,3000,2100,1300,860,1200,1900,2700,3150,3300,2900,2100,1300,860]
How do I perform a cos^2 (x) or a sin^2 (x) fit for the above data?I have the following x data and y data:
x = [0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180]
y = [880,1200,1900,2700,3300,3600,3000,2100,1300,860,1200,1900,2700,3150,3300,2900,2100,1300,860]
How do I perform a cos^2 (x) or a sin^2 (x) fit for the above data? I have the following x data and y data:
x = [0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180]
y = [880,1200,1900,2700,3300,3600,3000,2100,1300,860,1200,1900,2700,3150,3300,2900,2100,1300,860]
How do I perform a cos^2 (x) or a sin^2 (x) fit for the above data? curve fitting, matlab MATLAB Answers — New Questions
function file used with 2 Matrices as input
So the goal is to achieve correspondign AOU (oxygen data that can be compared to other types of O2 data) using two 4D matrixes (100 x 100 x 19 x 5 which is Longitude x Latitude x Depth x Time), one called SAL (giving Salinity values) and the other TEMP_K (Temperature in Kelvin).
The formula I want to use to calculate would be:
ln(O2 in µmol/kg) = – 173.9894 + 255.5907(100/TK) + 146.4813 ln(TK/100) – 22.2040(TK/100) + Sal [-0.037362 + 0.016504(TK/100) – 0.0020564(TK/100)2]
I tried to create a function file, giving me ln_AOU as well as AOU as output if I pull up the function, put it tells me there is an error ("Not enough input"). I think, there is something I’m generally missing, my experience with matlab is very limited, so I’d appreciate some help.
function [ln_AOU, AOU] = AOU(TEMP_K, SAL)
%Should transform the values of O2 into AOU
ln_AOU_TEMP = (- 173.9894) + 255.5907.*(100./TEMP_K) + 146.4813.* log(TEMP_K./100) – 22.2040*(TEMP_K./100) + SAL.*(0.016504.*(TEMP_K./100) – 0.0020564.*(TEMP_K./100).^2);
AOU = exp(ln_AOU);
endSo the goal is to achieve correspondign AOU (oxygen data that can be compared to other types of O2 data) using two 4D matrixes (100 x 100 x 19 x 5 which is Longitude x Latitude x Depth x Time), one called SAL (giving Salinity values) and the other TEMP_K (Temperature in Kelvin).
The formula I want to use to calculate would be:
ln(O2 in µmol/kg) = – 173.9894 + 255.5907(100/TK) + 146.4813 ln(TK/100) – 22.2040(TK/100) + Sal [-0.037362 + 0.016504(TK/100) – 0.0020564(TK/100)2]
I tried to create a function file, giving me ln_AOU as well as AOU as output if I pull up the function, put it tells me there is an error ("Not enough input"). I think, there is something I’m generally missing, my experience with matlab is very limited, so I’d appreciate some help.
function [ln_AOU, AOU] = AOU(TEMP_K, SAL)
%Should transform the values of O2 into AOU
ln_AOU_TEMP = (- 173.9894) + 255.5907.*(100./TEMP_K) + 146.4813.* log(TEMP_K./100) – 22.2040*(TEMP_K./100) + SAL.*(0.016504.*(TEMP_K./100) – 0.0020564.*(TEMP_K./100).^2);
AOU = exp(ln_AOU);
end So the goal is to achieve correspondign AOU (oxygen data that can be compared to other types of O2 data) using two 4D matrixes (100 x 100 x 19 x 5 which is Longitude x Latitude x Depth x Time), one called SAL (giving Salinity values) and the other TEMP_K (Temperature in Kelvin).
The formula I want to use to calculate would be:
ln(O2 in µmol/kg) = – 173.9894 + 255.5907(100/TK) + 146.4813 ln(TK/100) – 22.2040(TK/100) + Sal [-0.037362 + 0.016504(TK/100) – 0.0020564(TK/100)2]
I tried to create a function file, giving me ln_AOU as well as AOU as output if I pull up the function, put it tells me there is an error ("Not enough input"). I think, there is something I’m generally missing, my experience with matlab is very limited, so I’d appreciate some help.
function [ln_AOU, AOU] = AOU(TEMP_K, SAL)
%Should transform the values of O2 into AOU
ln_AOU_TEMP = (- 173.9894) + 255.5907.*(100./TEMP_K) + 146.4813.* log(TEMP_K./100) – 22.2040*(TEMP_K./100) + SAL.*(0.016504.*(TEMP_K./100) – 0.0020564.*(TEMP_K./100).^2);
AOU = exp(ln_AOU);
end function, matlab function, input, sum MATLAB Answers — New Questions
Command window execution by script editor automatically in a loop
Good morning,
I want to execute system commands through matlab and to run system command in a loop. System command is working fine for one iteration. Actually the problem is i have to run system command in a loop where system command runs multiple times until meets user criterio and then stop. So my question is when system command executed in second iteration in a loop user will have to give certain input to continue the process like below for loop to continue until it stops (not meeting criterio)
THese are the steps happen in command window after second iteration starts through system command in matlab.
Enter "exit" to end with restart save, "quit" to end without restart save. quit then press enter
Continue with interactive input options for control? <y or n> : y then press enter
Specify command (INTEractive, INCLude, STOP, etc.) STOP then press enter
So my question is . Is there a way to execute this commands automatically in command window without user interventi?Good morning,
I want to execute system commands through matlab and to run system command in a loop. System command is working fine for one iteration. Actually the problem is i have to run system command in a loop where system command runs multiple times until meets user criterio and then stop. So my question is when system command executed in second iteration in a loop user will have to give certain input to continue the process like below for loop to continue until it stops (not meeting criterio)
THese are the steps happen in command window after second iteration starts through system command in matlab.
Enter "exit" to end with restart save, "quit" to end without restart save. quit then press enter
Continue with interactive input options for control? <y or n> : y then press enter
Specify command (INTEractive, INCLude, STOP, etc.) STOP then press enter
So my question is . Is there a way to execute this commands automatically in command window without user interventi? Good morning,
I want to execute system commands through matlab and to run system command in a loop. System command is working fine for one iteration. Actually the problem is i have to run system command in a loop where system command runs multiple times until meets user criterio and then stop. So my question is when system command executed in second iteration in a loop user will have to give certain input to continue the process like below for loop to continue until it stops (not meeting criterio)
THese are the steps happen in command window after second iteration starts through system command in matlab.
Enter "exit" to end with restart save, "quit" to end without restart save. quit then press enter
Continue with interactive input options for control? <y or n> : y then press enter
Specify command (INTEractive, INCLude, STOP, etc.) STOP then press enter
So my question is . Is there a way to execute this commands automatically in command window without user interventi? system command, command window MATLAB Answers — New Questions
Indexing array of strings to the full string instead of one letter
Here is my array of strings:
propnames = [‘density’, ‘entropy’, ‘enthalpy’, ‘viscosity’, ‘Prandtl number’, ‘thermal conductivity’]
I’m trying to index to a particular string, but I can’t figure out how to get it to index the entire string instead of just one letter. For instance, "propnames(3)" returns ‘n’ (the ‘n’ in ‘density’) when I want it to return the string ‘enthalpy’. Does anyone know how to do this? I’d like to use a for loop from i = 1:6 to access each of these strings independently.
Thank you!Here is my array of strings:
propnames = [‘density’, ‘entropy’, ‘enthalpy’, ‘viscosity’, ‘Prandtl number’, ‘thermal conductivity’]
I’m trying to index to a particular string, but I can’t figure out how to get it to index the entire string instead of just one letter. For instance, "propnames(3)" returns ‘n’ (the ‘n’ in ‘density’) when I want it to return the string ‘enthalpy’. Does anyone know how to do this? I’d like to use a for loop from i = 1:6 to access each of these strings independently.
Thank you! Here is my array of strings:
propnames = [‘density’, ‘entropy’, ‘enthalpy’, ‘viscosity’, ‘Prandtl number’, ‘thermal conductivity’]
I’m trying to index to a particular string, but I can’t figure out how to get it to index the entire string instead of just one letter. For instance, "propnames(3)" returns ‘n’ (the ‘n’ in ‘density’) when I want it to return the string ‘enthalpy’. Does anyone know how to do this? I’d like to use a for loop from i = 1:6 to access each of these strings independently.
Thank you! strings, arrays MATLAB Answers — New Questions
How to rotate a parabola drawn along with the reference line?
I have an equation of calculating the radius of parabola for drawing specific maps. However, I could only draw parabola at origin.
For instance. I want to draw the parabola between two points at some known distance. In the code below, I have used the equation to plot the parabola when the line is horizontal and starts at original. For finding the xy coordinates, I use the cosine and sine components and then plot.
However, in cases where I have the same distance between the points but not at origin (I tried xy coordinates with same magnitude but different location and rotation), I cannot construct the rotated parabola. Is there a way to draw the rotated parabola?
Additionally, my way is inspired from `excel` and is very unituitive. Is there a more convenient way to construct parabola in Matlab?
clc
clear all
close all
%% Input values
D = 250; % mm distance
c = 4; % mm/s velocity
del = 10; % a constant
theta = deg2rad(0:5:360); % a variable
for i = 1:length(theta)
angle = theta(i);
R(i) = 1/2*(D*D – del*del*c*c)/(del*c + D*cos(angle)); % Equation of radius of parabola
x1(i) = 0;
y1(i) = 0;
x2(i) = R(i)*cos(angle);
y2(i) = R(i)*sin(angle);
end
pta = [0 250];
ptb = [0 0];
figure
tiledlayout(2,1)
nexttile
hold on
plot(pta,ptb,’-o’);
plot(x2,y2,’.r’)
xlim([0 D])
nexttile
hold on
ptc = [50 250];
ptd = [40 190];
plot(ptc,ptd,’-o’);
xlim([0 250])
ylim([0 250])
There may be a simple solution, forgive my trignomatry skills and I will appreciate your help in this regard.
All the best.I have an equation of calculating the radius of parabola for drawing specific maps. However, I could only draw parabola at origin.
For instance. I want to draw the parabola between two points at some known distance. In the code below, I have used the equation to plot the parabola when the line is horizontal and starts at original. For finding the xy coordinates, I use the cosine and sine components and then plot.
However, in cases where I have the same distance between the points but not at origin (I tried xy coordinates with same magnitude but different location and rotation), I cannot construct the rotated parabola. Is there a way to draw the rotated parabola?
Additionally, my way is inspired from `excel` and is very unituitive. Is there a more convenient way to construct parabola in Matlab?
clc
clear all
close all
%% Input values
D = 250; % mm distance
c = 4; % mm/s velocity
del = 10; % a constant
theta = deg2rad(0:5:360); % a variable
for i = 1:length(theta)
angle = theta(i);
R(i) = 1/2*(D*D – del*del*c*c)/(del*c + D*cos(angle)); % Equation of radius of parabola
x1(i) = 0;
y1(i) = 0;
x2(i) = R(i)*cos(angle);
y2(i) = R(i)*sin(angle);
end
pta = [0 250];
ptb = [0 0];
figure
tiledlayout(2,1)
nexttile
hold on
plot(pta,ptb,’-o’);
plot(x2,y2,’.r’)
xlim([0 D])
nexttile
hold on
ptc = [50 250];
ptd = [40 190];
plot(ptc,ptd,’-o’);
xlim([0 250])
ylim([0 250])
There may be a simple solution, forgive my trignomatry skills and I will appreciate your help in this regard.
All the best. I have an equation of calculating the radius of parabola for drawing specific maps. However, I could only draw parabola at origin.
For instance. I want to draw the parabola between two points at some known distance. In the code below, I have used the equation to plot the parabola when the line is horizontal and starts at original. For finding the xy coordinates, I use the cosine and sine components and then plot.
However, in cases where I have the same distance between the points but not at origin (I tried xy coordinates with same magnitude but different location and rotation), I cannot construct the rotated parabola. Is there a way to draw the rotated parabola?
Additionally, my way is inspired from `excel` and is very unituitive. Is there a more convenient way to construct parabola in Matlab?
clc
clear all
close all
%% Input values
D = 250; % mm distance
c = 4; % mm/s velocity
del = 10; % a constant
theta = deg2rad(0:5:360); % a variable
for i = 1:length(theta)
angle = theta(i);
R(i) = 1/2*(D*D – del*del*c*c)/(del*c + D*cos(angle)); % Equation of radius of parabola
x1(i) = 0;
y1(i) = 0;
x2(i) = R(i)*cos(angle);
y2(i) = R(i)*sin(angle);
end
pta = [0 250];
ptb = [0 0];
figure
tiledlayout(2,1)
nexttile
hold on
plot(pta,ptb,’-o’);
plot(x2,y2,’.r’)
xlim([0 D])
nexttile
hold on
ptc = [50 250];
ptd = [40 190];
plot(ptc,ptd,’-o’);
xlim([0 250])
ylim([0 250])
There may be a simple solution, forgive my trignomatry skills and I will appreciate your help in this regard.
All the best. parabol, transformation, rotation, translation MATLAB Answers — New Questions
Proper phrasing of error bars in an essay
Hi,
I have used custom option on the cftool for curve fitting of my data using my formula of interest. To extract the error bars of the fit parameters, I used the confint MATLAB tool. How can I phrase the error bars on my fit in scientifically correct terms? Any better or more precise phrasing compared to the following sentence?
The error bars are the goodness of the fit with 95% confidence bounds.
Best wishes,
MohaHi,
I have used custom option on the cftool for curve fitting of my data using my formula of interest. To extract the error bars of the fit parameters, I used the confint MATLAB tool. How can I phrase the error bars on my fit in scientifically correct terms? Any better or more precise phrasing compared to the following sentence?
The error bars are the goodness of the fit with 95% confidence bounds.
Best wishes,
Moha Hi,
I have used custom option on the cftool for curve fitting of my data using my formula of interest. To extract the error bars of the fit parameters, I used the confint MATLAB tool. How can I phrase the error bars on my fit in scientifically correct terms? Any better or more precise phrasing compared to the following sentence?
The error bars are the goodness of the fit with 95% confidence bounds.
Best wishes,
Moha curve fitting, scientific writing MATLAB Answers — New Questions
BVP Error, help with explaination
Hello all,
I am struggeling a bit with understanding why I get an error message here. The code works fine with bigger numbers for A or with smaller numbers for B but is crashing for example with the given parameters. I already figured that y(1) is becoming NaN at some point which causes the code to crash. Could somebody help me understand why this is happening?
bvp()
function bvp
A = 50e-3;
B = 1;
xmesh = linspace(0, 1, 100);
sol_init = bvpinit(xmesh, @init);
sol = bvp4c(@ode, @bcfun, sol_init);
function dydx = ode(x, y)
dydx(1) = y(2);
dydx(2) = exp(y(1)*log(10)/A);
%disp(y(1))
end
% Define the boundary conditions
function res = bcfun(ya, yb)
res(1) = ya(1) – B;
res(2) = yb(1);
end
% Define the initial guess for the solution
function guess = init(x)
guess(1) = B;
guess(2) = 0;
end
endHello all,
I am struggeling a bit with understanding why I get an error message here. The code works fine with bigger numbers for A or with smaller numbers for B but is crashing for example with the given parameters. I already figured that y(1) is becoming NaN at some point which causes the code to crash. Could somebody help me understand why this is happening?
bvp()
function bvp
A = 50e-3;
B = 1;
xmesh = linspace(0, 1, 100);
sol_init = bvpinit(xmesh, @init);
sol = bvp4c(@ode, @bcfun, sol_init);
function dydx = ode(x, y)
dydx(1) = y(2);
dydx(2) = exp(y(1)*log(10)/A);
%disp(y(1))
end
% Define the boundary conditions
function res = bcfun(ya, yb)
res(1) = ya(1) – B;
res(2) = yb(1);
end
% Define the initial guess for the solution
function guess = init(x)
guess(1) = B;
guess(2) = 0;
end
end Hello all,
I am struggeling a bit with understanding why I get an error message here. The code works fine with bigger numbers for A or with smaller numbers for B but is crashing for example with the given parameters. I already figured that y(1) is becoming NaN at some point which causes the code to crash. Could somebody help me understand why this is happening?
bvp()
function bvp
A = 50e-3;
B = 1;
xmesh = linspace(0, 1, 100);
sol_init = bvpinit(xmesh, @init);
sol = bvp4c(@ode, @bcfun, sol_init);
function dydx = ode(x, y)
dydx(1) = y(2);
dydx(2) = exp(y(1)*log(10)/A);
%disp(y(1))
end
% Define the boundary conditions
function res = bcfun(ya, yb)
res(1) = ya(1) – B;
res(2) = yb(1);
end
% Define the initial guess for the solution
function guess = init(x)
guess(1) = B;
guess(2) = 0;
end
end bvp, ode, ode45, differential equations MATLAB Answers — New Questions
Deep Learning FPGA Deployment on Xilinx ZCU102
I would like to Run a Deep Learning Networks on Xilinx ZCU102 board, as shown here: Run a Deep Learning Network on FPGA with Live Camera Input – MATLAB & Simulink (mathworks.com)
But I can’t find the model "Deep Learning Pre-Process Hardware Algorithm Target Model" mentioned in the link.
Would it be possible to get an off-line model ?
My matlab version is R2021a.
Thanks in advance.I would like to Run a Deep Learning Networks on Xilinx ZCU102 board, as shown here: Run a Deep Learning Network on FPGA with Live Camera Input – MATLAB & Simulink (mathworks.com)
But I can’t find the model "Deep Learning Pre-Process Hardware Algorithm Target Model" mentioned in the link.
Would it be possible to get an off-line model ?
My matlab version is R2021a.
Thanks in advance. I would like to Run a Deep Learning Networks on Xilinx ZCU102 board, as shown here: Run a Deep Learning Network on FPGA with Live Camera Input – MATLAB & Simulink (mathworks.com)
But I can’t find the model "Deep Learning Pre-Process Hardware Algorithm Target Model" mentioned in the link.
Would it be possible to get an off-line model ?
My matlab version is R2021a.
Thanks in advance. zcu102, deep learning MATLAB Answers — New Questions
Training, validating, and testing model.
Hi,
I have written three linear regression models and would like to know how to train, validate, and thest them with a random 60 20 20 split. any help would be much appreciated. here is the code.
PTT = filtered_BP_Data(:, 1);
systolicBP = filtered_BP_Data(:, 2);
diastolicBP = filtered_BP_Data(:, 3);
avgBP = filtered_BP_Data(:, 4);
lm1 = fitlm(PTT, systolicBP);
disp(lm1);
% plot PTT vs systolic BP
figure;
scatter(PTT, systolicBP, ‘x’);
hold on;
regressionLine1 = lm1.Coefficients.Estimate(1) + lm1.Coefficients.Estimate(2) * PTT;
plot(PTT, regressionLine1, ‘-r’);
xlabel(‘PTT (ms)’);
ylabel(‘Systolic Blood Pressure (mmHg)’);
title(‘Average PTT vs Systolic BP’);
legend(‘Data Points’, ‘Location’, ‘best’);
grid on;
hold off;
lm2 = fitlm(PTT, diastolicBP);
disp(lm2);
% plot PTT vs diastolic BP
figure;
scatter(PTT, diastolicBP, ‘x’);
hold on;
regressionLine2 = lm2.Coefficients.Estimate(1) + lm2.Coefficients.Estimate(2) * PTT;
plot(PTT, regressionLine2, ‘-r’);
xlabel(‘PTT (ms)’);
ylabel(‘Diastolic Blood Pressure (mmHg)’);
title(‘Average PTT vs Diastolic BP’);
legend(‘Data Points’, ‘Location’, ‘best’);
grid on;
hold off;
lm3 = fitlm(PTT, avgBP);
disp(lm3);
% plot PTT vs avg BP
figure;
scatter(PTT, avgBP, ‘x’);
hold on;
regressionLine3 = lm3.Coefficients.Estimate(1) + lm3.Coefficients.Estimate(2) * PTT;
plot(PTT, regressionLine3, ‘-r’);
xlabel(‘PTT (ms)’);
ylabel(‘Avg Blood Pressure (mmHg)’);
title(‘Average PTT vs Avg BP’);
legend(‘Data Points’, ‘Location’, ‘best’);
grid on;
hold off;Hi,
I have written three linear regression models and would like to know how to train, validate, and thest them with a random 60 20 20 split. any help would be much appreciated. here is the code.
PTT = filtered_BP_Data(:, 1);
systolicBP = filtered_BP_Data(:, 2);
diastolicBP = filtered_BP_Data(:, 3);
avgBP = filtered_BP_Data(:, 4);
lm1 = fitlm(PTT, systolicBP);
disp(lm1);
% plot PTT vs systolic BP
figure;
scatter(PTT, systolicBP, ‘x’);
hold on;
regressionLine1 = lm1.Coefficients.Estimate(1) + lm1.Coefficients.Estimate(2) * PTT;
plot(PTT, regressionLine1, ‘-r’);
xlabel(‘PTT (ms)’);
ylabel(‘Systolic Blood Pressure (mmHg)’);
title(‘Average PTT vs Systolic BP’);
legend(‘Data Points’, ‘Location’, ‘best’);
grid on;
hold off;
lm2 = fitlm(PTT, diastolicBP);
disp(lm2);
% plot PTT vs diastolic BP
figure;
scatter(PTT, diastolicBP, ‘x’);
hold on;
regressionLine2 = lm2.Coefficients.Estimate(1) + lm2.Coefficients.Estimate(2) * PTT;
plot(PTT, regressionLine2, ‘-r’);
xlabel(‘PTT (ms)’);
ylabel(‘Diastolic Blood Pressure (mmHg)’);
title(‘Average PTT vs Diastolic BP’);
legend(‘Data Points’, ‘Location’, ‘best’);
grid on;
hold off;
lm3 = fitlm(PTT, avgBP);
disp(lm3);
% plot PTT vs avg BP
figure;
scatter(PTT, avgBP, ‘x’);
hold on;
regressionLine3 = lm3.Coefficients.Estimate(1) + lm3.Coefficients.Estimate(2) * PTT;
plot(PTT, regressionLine3, ‘-r’);
xlabel(‘PTT (ms)’);
ylabel(‘Avg Blood Pressure (mmHg)’);
title(‘Average PTT vs Avg BP’);
legend(‘Data Points’, ‘Location’, ‘best’);
grid on;
hold off; Hi,
I have written three linear regression models and would like to know how to train, validate, and thest them with a random 60 20 20 split. any help would be much appreciated. here is the code.
PTT = filtered_BP_Data(:, 1);
systolicBP = filtered_BP_Data(:, 2);
diastolicBP = filtered_BP_Data(:, 3);
avgBP = filtered_BP_Data(:, 4);
lm1 = fitlm(PTT, systolicBP);
disp(lm1);
% plot PTT vs systolic BP
figure;
scatter(PTT, systolicBP, ‘x’);
hold on;
regressionLine1 = lm1.Coefficients.Estimate(1) + lm1.Coefficients.Estimate(2) * PTT;
plot(PTT, regressionLine1, ‘-r’);
xlabel(‘PTT (ms)’);
ylabel(‘Systolic Blood Pressure (mmHg)’);
title(‘Average PTT vs Systolic BP’);
legend(‘Data Points’, ‘Location’, ‘best’);
grid on;
hold off;
lm2 = fitlm(PTT, diastolicBP);
disp(lm2);
% plot PTT vs diastolic BP
figure;
scatter(PTT, diastolicBP, ‘x’);
hold on;
regressionLine2 = lm2.Coefficients.Estimate(1) + lm2.Coefficients.Estimate(2) * PTT;
plot(PTT, regressionLine2, ‘-r’);
xlabel(‘PTT (ms)’);
ylabel(‘Diastolic Blood Pressure (mmHg)’);
title(‘Average PTT vs Diastolic BP’);
legend(‘Data Points’, ‘Location’, ‘best’);
grid on;
hold off;
lm3 = fitlm(PTT, avgBP);
disp(lm3);
% plot PTT vs avg BP
figure;
scatter(PTT, avgBP, ‘x’);
hold on;
regressionLine3 = lm3.Coefficients.Estimate(1) + lm3.Coefficients.Estimate(2) * PTT;
plot(PTT, regressionLine3, ‘-r’);
xlabel(‘PTT (ms)’);
ylabel(‘Avg Blood Pressure (mmHg)’);
title(‘Average PTT vs Avg BP’);
legend(‘Data Points’, ‘Location’, ‘best’);
grid on;
hold off; linear regression, machine learning, statistics, data-analysis MATLAB Answers — New Questions
Force symbolic simplification to eliminate variable
When breaking down a (long and complex) formula into the form , I use the approach of the lincoeffs script.
The problem is, that I still have in b, because simplification isn’t detecting that the terms cancel out.
Is there a trick to force the elimination of -terms?
The symbolic expression is attached if you want to try it, the code is as follows:
% NOT WORKING – extract coefficients of ddddh_fun
syms u
% ddddh_fun = expand(ddddh_fun);
ddddh_fun_formula = formula(ddddh_fun) == 0;
[ddddh_fun_A,ddddh_fun_b] = lincoeffs(ddddh_fun_formula,u)
ddddh_fun_b = simplify(ddddh_fun_b,’Steps’,50);
—
% WORKING – extract coefficients of ddddh_fun
syms u
ddddh_fun = expand(ddddh_fun);
ddddh_fun_formula = formula(ddddh_fun) == 0;
[ddddh_fun_A,ddddh_fun_b] = lincoeffs(ddddh_fun_formula,u)
ddddh_fun_b = simplify(ddddh_fun_b,’Steps’,50);
The problem with this is, that the very expanded expression from the working version isn’t very readable when I do export is as Latex, which is necessary for me.
To read the symbolic function and the matlabFunction derived from this is also very hard this way.When breaking down a (long and complex) formula into the form , I use the approach of the lincoeffs script.
The problem is, that I still have in b, because simplification isn’t detecting that the terms cancel out.
Is there a trick to force the elimination of -terms?
The symbolic expression is attached if you want to try it, the code is as follows:
% NOT WORKING – extract coefficients of ddddh_fun
syms u
% ddddh_fun = expand(ddddh_fun);
ddddh_fun_formula = formula(ddddh_fun) == 0;
[ddddh_fun_A,ddddh_fun_b] = lincoeffs(ddddh_fun_formula,u)
ddddh_fun_b = simplify(ddddh_fun_b,’Steps’,50);
—
% WORKING – extract coefficients of ddddh_fun
syms u
ddddh_fun = expand(ddddh_fun);
ddddh_fun_formula = formula(ddddh_fun) == 0;
[ddddh_fun_A,ddddh_fun_b] = lincoeffs(ddddh_fun_formula,u)
ddddh_fun_b = simplify(ddddh_fun_b,’Steps’,50);
The problem with this is, that the very expanded expression from the working version isn’t very readable when I do export is as Latex, which is necessary for me.
To read the symbolic function and the matlabFunction derived from this is also very hard this way. When breaking down a (long and complex) formula into the form , I use the approach of the lincoeffs script.
The problem is, that I still have in b, because simplification isn’t detecting that the terms cancel out.
Is there a trick to force the elimination of -terms?
The symbolic expression is attached if you want to try it, the code is as follows:
% NOT WORKING – extract coefficients of ddddh_fun
syms u
% ddddh_fun = expand(ddddh_fun);
ddddh_fun_formula = formula(ddddh_fun) == 0;
[ddddh_fun_A,ddddh_fun_b] = lincoeffs(ddddh_fun_formula,u)
ddddh_fun_b = simplify(ddddh_fun_b,’Steps’,50);
—
% WORKING – extract coefficients of ddddh_fun
syms u
ddddh_fun = expand(ddddh_fun);
ddddh_fun_formula = formula(ddddh_fun) == 0;
[ddddh_fun_A,ddddh_fun_b] = lincoeffs(ddddh_fun_formula,u)
ddddh_fun_b = simplify(ddddh_fun_b,’Steps’,50);
The problem with this is, that the very expanded expression from the working version isn’t very readable when I do export is as Latex, which is necessary for me.
To read the symbolic function and the matlabFunction derived from this is also very hard this way. symbolic, elimination of terms with variable, simplify MATLAB Answers — New Questions
how to know the total counts in liver
Hi All,
Let say i fused image between PET and CT.
Then in liver area, i got some uptake.
Then how to calculate the counts in the whole liver?
Anyone can help me?Hi All,
Let say i fused image between PET and CT.
Then in liver area, i got some uptake.
Then how to calculate the counts in the whole liver?
Anyone can help me? Hi All,
Let say i fused image between PET and CT.
Then in liver area, i got some uptake.
Then how to calculate the counts in the whole liver?
Anyone can help me? image processing, digital image processing, image analysis, image segmentation, image acquisition MATLAB Answers — New Questions
Solving a linear programming problem uising linprog
I have the given linear program to solve.
To solve this I prepare the following for the constraints on each of the six variables:
A = [110 205 160 160 420 260;
4 32 13 8 4 14;
2 12 54 285 22 80];
b = [2000 55 800];
where the function to be minimized with constraints:
f = [3 24 13 9 20 19];
lb = [0,0,0,0,0,0];
ub = [4,3,2,8,2,2];
Is solved by:
options = optimoptions(‘linprog’,’Algorithm’,’dual-simplex’);
[x,fval,exitflag,output] = linprog(f,A,b,lb,ub,options)
.
I get "Error using linprog (line 182)
LINPROG requires the following inputs to be of data type double: ‘LB’"
How do I prepare the linear inequalities correctly?
With ThanksI have the given linear program to solve.
To solve this I prepare the following for the constraints on each of the six variables:
A = [110 205 160 160 420 260;
4 32 13 8 4 14;
2 12 54 285 22 80];
b = [2000 55 800];
where the function to be minimized with constraints:
f = [3 24 13 9 20 19];
lb = [0,0,0,0,0,0];
ub = [4,3,2,8,2,2];
Is solved by:
options = optimoptions(‘linprog’,’Algorithm’,’dual-simplex’);
[x,fval,exitflag,output] = linprog(f,A,b,lb,ub,options)
.
I get "Error using linprog (line 182)
LINPROG requires the following inputs to be of data type double: ‘LB’"
How do I prepare the linear inequalities correctly?
With Thanks I have the given linear program to solve.
To solve this I prepare the following for the constraints on each of the six variables:
A = [110 205 160 160 420 260;
4 32 13 8 4 14;
2 12 54 285 22 80];
b = [2000 55 800];
where the function to be minimized with constraints:
f = [3 24 13 9 20 19];
lb = [0,0,0,0,0,0];
ub = [4,3,2,8,2,2];
Is solved by:
options = optimoptions(‘linprog’,’Algorithm’,’dual-simplex’);
[x,fval,exitflag,output] = linprog(f,A,b,lb,ub,options)
.
I get "Error using linprog (line 182)
LINPROG requires the following inputs to be of data type double: ‘LB’"
How do I prepare the linear inequalities correctly?
With Thanks linear programming, linprog MATLAB Answers — New Questions
How to know if an RL agent has been updated
Hi all,
I want to train an RL agent, but would like to make sure that my agent is updated, so I want to ask how to see if the agent has been updated.
For example, in the official example of ‘rl/TrainMultipleAgentsForAreaCoverageExample’, I extracted the code related to the agent definition, the training and the simulation:
%…
agentA = rlPPOAgent(actor(1),critic(1),opt);
agentB = rlPPOAgent(actor(2),critic(2),opt);
agentC = rlPPOAgent(actor(3),critic(3),opt);
%…
if doTraining
result = train([agentA,agentB,agentC],env,trainOpts);
else
load("rlAreaCoverageAgents.mat");
end
%…
rng(0) % reset the random seed
simOpts = rlSimulationOptions(MaxSteps=maxsteps);
experience = sim(env,[agentA,agentB,agentC],simOpts);
However, say after training I would like to do a check on whether the agentA has changed or not:
copy = agentA;
%the above code section where agentA is trained…
disp(copy==agentA)
The result displayed is 1, so agentA has not been changed?
But this is from the official example so I believe the agents should indeed have been trained. And the simulation result also suggests that they have been trained since it takes sufficiently longer for an agent before train() to complete the task than the one after train().
It seems that train() does update agents, but how can I explicitly tell from the variables in my workspace that they are indeed updated? And why he above comparison is not working? Thank you.
Haochen TaoHi all,
I want to train an RL agent, but would like to make sure that my agent is updated, so I want to ask how to see if the agent has been updated.
For example, in the official example of ‘rl/TrainMultipleAgentsForAreaCoverageExample’, I extracted the code related to the agent definition, the training and the simulation:
%…
agentA = rlPPOAgent(actor(1),critic(1),opt);
agentB = rlPPOAgent(actor(2),critic(2),opt);
agentC = rlPPOAgent(actor(3),critic(3),opt);
%…
if doTraining
result = train([agentA,agentB,agentC],env,trainOpts);
else
load("rlAreaCoverageAgents.mat");
end
%…
rng(0) % reset the random seed
simOpts = rlSimulationOptions(MaxSteps=maxsteps);
experience = sim(env,[agentA,agentB,agentC],simOpts);
However, say after training I would like to do a check on whether the agentA has changed or not:
copy = agentA;
%the above code section where agentA is trained…
disp(copy==agentA)
The result displayed is 1, so agentA has not been changed?
But this is from the official example so I believe the agents should indeed have been trained. And the simulation result also suggests that they have been trained since it takes sufficiently longer for an agent before train() to complete the task than the one after train().
It seems that train() does update agents, but how can I explicitly tell from the variables in my workspace that they are indeed updated? And why he above comparison is not working? Thank you.
Haochen Tao Hi all,
I want to train an RL agent, but would like to make sure that my agent is updated, so I want to ask how to see if the agent has been updated.
For example, in the official example of ‘rl/TrainMultipleAgentsForAreaCoverageExample’, I extracted the code related to the agent definition, the training and the simulation:
%…
agentA = rlPPOAgent(actor(1),critic(1),opt);
agentB = rlPPOAgent(actor(2),critic(2),opt);
agentC = rlPPOAgent(actor(3),critic(3),opt);
%…
if doTraining
result = train([agentA,agentB,agentC],env,trainOpts);
else
load("rlAreaCoverageAgents.mat");
end
%…
rng(0) % reset the random seed
simOpts = rlSimulationOptions(MaxSteps=maxsteps);
experience = sim(env,[agentA,agentB,agentC],simOpts);
However, say after training I would like to do a check on whether the agentA has changed or not:
copy = agentA;
%the above code section where agentA is trained…
disp(copy==agentA)
The result displayed is 1, so agentA has not been changed?
But this is from the official example so I believe the agents should indeed have been trained. And the simulation result also suggests that they have been trained since it takes sufficiently longer for an agent before train() to complete the task than the one after train().
It seems that train() does update agents, but how can I explicitly tell from the variables in my workspace that they are indeed updated? And why he above comparison is not working? Thank you.
Haochen Tao reinforcement learning, agent MATLAB Answers — New Questions
Animating pcolor plots to show evolution?
Is there a way to animate a pcolor plot? Like have the y axis gradually fill with my simulation data?Is there a way to animate a pcolor plot? Like have the y axis gradually fill with my simulation data? Is there a way to animate a pcolor plot? Like have the y axis gradually fill with my simulation data? pcolor, plotting, video MATLAB Answers — New Questions
Error due to “zero” eigenvalues
I’m following this documentation: Model an Excavator Dipper Arm as a Flexible Body – MATLAB & Simulink (mathworks.com).
I copied the entire code and it works with the Dipper.STL file, but for every other STL file i import, I get the ‘zero eigenvalue" error mentioned in the title. The simplest STL file I used was a cube modeled in spaceclaim (10 x 10 x 60 mm). I’ve varied the mesh fineness to be on a spectrum similar to the dipper arm.
I’ve looked at all settings and not figured out what might be wrong. I also added a fixed support for the first frame; didn’t make a difference. It’s also worthy noting that the stiffness matrix seemed to have non-zero values just the first few rows, but the rest seemd to be absolutely zero. Here’s the entire thing.
clear
clc
cd(‘G:My DriveStudiesM.Sc. Mechanical Engineering24 SMMatlabBeam_Atli’)
stlFile = ‘beam_Atli2.stl’;
figure
trisurf(stlread(stlFile))
axis equal
E = 10e9; % Young’s modulus in Pa
nu = 0.26; % Poisson’s ratio (nondimensional)
rho = 7800; % Mass density in kg/m^3
origins = [60 0.5 -5 % Frame 1: Cylinder connection point
30 0.5 0 % Frame 2: Bucket connection point
0 0.5 -5]; % Frame 3: Fulcrum point
numFrames = size(origins,1);
feModel = createpde(‘structural’,’modal-solid’);
importGeometry(feModel,stlFile);
structuralProperties(feModel, …
‘YoungsModulus’,E, …
‘PoissonsRatio’,nu, …
‘MassDensity’,rho);
generateMesh(feModel, …
‘GeometricOrder’,’quadratic’, …
‘Hmax’,2.5, …
‘Hmin’,0.25);
figure
pdegplot(feModel,’FaceLabels’,’on’,’FaceAlpha’,0.5)
faceIDs = [1,2,3]; % List in the same order as the interface frame origins
figure
pdemesh(feModel,’FaceAlpha’,0.5)
hold on
colors = [‘rgb’ repmat(‘k’,1,numFrames-3)];
assert(numel(faceIDs) == numFrames);
for k = 1:numFrames
nodeIdxs = findNodes(feModel.Mesh,’region’,’Face’,faceIDs(k));
scatter3( …
feModel.Mesh.Nodes(1,nodeIdxs), …
feModel.Mesh.Nodes(2,nodeIdxs), …
feModel.Mesh.Nodes(3,nodeIdxs), …
‘ok’,’MarkerFaceColor’,colors(k))
scatter3( …
origins(k,1), …
origins(k,2), …
origins(k,3), …
80,colors(k),’filled’,’s’)
end
hold off
structuralBC(feModel, ‘Face’, faceIDs(1), ‘Constraint’, ‘fixed’);
for k = 1:numFrames
structuralBC(feModel, …
‘Face’,faceIDs(k), …
‘Constraint’,’multipoint’, …
‘Reference’,origins(k,:));
end
rom = reduce(feModel,’FrequencyRange’,[0 1e4]);
arm.P = rom.ReferenceLocations’; % Interface frame locations (n x 3 matrix)
arm.K = rom.K; % Reduced stiffness matrix
arm.M = rom.M; % Reduced mass matrix
dampingRatio = 0.05;
arm.C = computeModalDampingMatrix(dampingRatio,rom.K,rom.M);
frmPerm = zeros(numFrames,1); % Frame permutation vector
dofPerm = 1:size(arm.K,1); % DOF permutation vector
assert(size(arm.P,1) == numFrames);
for i = 1:numFrames
for j = 1:numFrames
if isequal(arm.P(j,:),origins(i,:))
frmPerm(i) = j;
dofPerm(6*(i-1)+(1:6)) = 6*(j-1)+(1:6);
continue;
end
end
end
assert(numel(frmPerm) == numFrames);
assert(numel(dofPerm) == size(arm.K,1));
arm.P = arm.P(frmPerm,:);
arm.K = arm.K(dofPerm,:);
arm.K = arm.K(:,dofPerm);
arm.M = arm.M(dofPerm,:);
arm.M = arm.M(:,dofPerm);
arm.C = arm.C(dofPerm,:);
arm.C = arm.C(:,dofPerm);
function C = computeModalDampingMatrix(dampingRatio,K,M)
% To avoid numerical issues (such as complex eigenvalues with very small
% imaginary parts), make the matrices exactly symmetric.
K = (K+K’)/2; % Stiffness matrix
M = (M+M’)/2; % Mass matrix
% Compute the eigen-decomposition associated with the mass and stiffness
% matrices, sorting the eigenvalues in ascending order and permuting
% the corresponding eigenvectors.
[V,D] = eig(K,M);
[d,sortIdxs] = sort(diag(D));
V = V(:,sortIdxs);
% Due to small numerical errors, the six eigenvalues associated with the
% rigid-body modes may not be exactly zero. To avoid numerical issues,
% check that the first six eigenvalues are close enough to zero. Then
% replace them with exact 0 values.
assert(all(abs(d(1:6))/abs(d(7)) < 1e-9),’Error due to "zero" eigenvalues.’);
d(1:6) = 0;
% Vectors of generalized masses and natural frequencies
MV = M*V;
generalizedMasses = diag(V’*MV);
naturalFrequencies = sqrt(d);
% Compute the modal damping matrix associated with K and M
C = MV * diag(2*dampingRatio*naturalFrequencies./generalizedMasses) * MV’;
% Print the eigenmodes
disp(‘Eigenmodes (eigenvectors) V:’);
disp(V);
disp(‘Eigenvalues D:’);
disp(d);
endI’m following this documentation: Model an Excavator Dipper Arm as a Flexible Body – MATLAB & Simulink (mathworks.com).
I copied the entire code and it works with the Dipper.STL file, but for every other STL file i import, I get the ‘zero eigenvalue" error mentioned in the title. The simplest STL file I used was a cube modeled in spaceclaim (10 x 10 x 60 mm). I’ve varied the mesh fineness to be on a spectrum similar to the dipper arm.
I’ve looked at all settings and not figured out what might be wrong. I also added a fixed support for the first frame; didn’t make a difference. It’s also worthy noting that the stiffness matrix seemed to have non-zero values just the first few rows, but the rest seemd to be absolutely zero. Here’s the entire thing.
clear
clc
cd(‘G:My DriveStudiesM.Sc. Mechanical Engineering24 SMMatlabBeam_Atli’)
stlFile = ‘beam_Atli2.stl’;
figure
trisurf(stlread(stlFile))
axis equal
E = 10e9; % Young’s modulus in Pa
nu = 0.26; % Poisson’s ratio (nondimensional)
rho = 7800; % Mass density in kg/m^3
origins = [60 0.5 -5 % Frame 1: Cylinder connection point
30 0.5 0 % Frame 2: Bucket connection point
0 0.5 -5]; % Frame 3: Fulcrum point
numFrames = size(origins,1);
feModel = createpde(‘structural’,’modal-solid’);
importGeometry(feModel,stlFile);
structuralProperties(feModel, …
‘YoungsModulus’,E, …
‘PoissonsRatio’,nu, …
‘MassDensity’,rho);
generateMesh(feModel, …
‘GeometricOrder’,’quadratic’, …
‘Hmax’,2.5, …
‘Hmin’,0.25);
figure
pdegplot(feModel,’FaceLabels’,’on’,’FaceAlpha’,0.5)
faceIDs = [1,2,3]; % List in the same order as the interface frame origins
figure
pdemesh(feModel,’FaceAlpha’,0.5)
hold on
colors = [‘rgb’ repmat(‘k’,1,numFrames-3)];
assert(numel(faceIDs) == numFrames);
for k = 1:numFrames
nodeIdxs = findNodes(feModel.Mesh,’region’,’Face’,faceIDs(k));
scatter3( …
feModel.Mesh.Nodes(1,nodeIdxs), …
feModel.Mesh.Nodes(2,nodeIdxs), …
feModel.Mesh.Nodes(3,nodeIdxs), …
‘ok’,’MarkerFaceColor’,colors(k))
scatter3( …
origins(k,1), …
origins(k,2), …
origins(k,3), …
80,colors(k),’filled’,’s’)
end
hold off
structuralBC(feModel, ‘Face’, faceIDs(1), ‘Constraint’, ‘fixed’);
for k = 1:numFrames
structuralBC(feModel, …
‘Face’,faceIDs(k), …
‘Constraint’,’multipoint’, …
‘Reference’,origins(k,:));
end
rom = reduce(feModel,’FrequencyRange’,[0 1e4]);
arm.P = rom.ReferenceLocations’; % Interface frame locations (n x 3 matrix)
arm.K = rom.K; % Reduced stiffness matrix
arm.M = rom.M; % Reduced mass matrix
dampingRatio = 0.05;
arm.C = computeModalDampingMatrix(dampingRatio,rom.K,rom.M);
frmPerm = zeros(numFrames,1); % Frame permutation vector
dofPerm = 1:size(arm.K,1); % DOF permutation vector
assert(size(arm.P,1) == numFrames);
for i = 1:numFrames
for j = 1:numFrames
if isequal(arm.P(j,:),origins(i,:))
frmPerm(i) = j;
dofPerm(6*(i-1)+(1:6)) = 6*(j-1)+(1:6);
continue;
end
end
end
assert(numel(frmPerm) == numFrames);
assert(numel(dofPerm) == size(arm.K,1));
arm.P = arm.P(frmPerm,:);
arm.K = arm.K(dofPerm,:);
arm.K = arm.K(:,dofPerm);
arm.M = arm.M(dofPerm,:);
arm.M = arm.M(:,dofPerm);
arm.C = arm.C(dofPerm,:);
arm.C = arm.C(:,dofPerm);
function C = computeModalDampingMatrix(dampingRatio,K,M)
% To avoid numerical issues (such as complex eigenvalues with very small
% imaginary parts), make the matrices exactly symmetric.
K = (K+K’)/2; % Stiffness matrix
M = (M+M’)/2; % Mass matrix
% Compute the eigen-decomposition associated with the mass and stiffness
% matrices, sorting the eigenvalues in ascending order and permuting
% the corresponding eigenvectors.
[V,D] = eig(K,M);
[d,sortIdxs] = sort(diag(D));
V = V(:,sortIdxs);
% Due to small numerical errors, the six eigenvalues associated with the
% rigid-body modes may not be exactly zero. To avoid numerical issues,
% check that the first six eigenvalues are close enough to zero. Then
% replace them with exact 0 values.
assert(all(abs(d(1:6))/abs(d(7)) < 1e-9),’Error due to "zero" eigenvalues.’);
d(1:6) = 0;
% Vectors of generalized masses and natural frequencies
MV = M*V;
generalizedMasses = diag(V’*MV);
naturalFrequencies = sqrt(d);
% Compute the modal damping matrix associated with K and M
C = MV * diag(2*dampingRatio*naturalFrequencies./generalizedMasses) * MV’;
% Print the eigenmodes
disp(‘Eigenmodes (eigenvectors) V:’);
disp(V);
disp(‘Eigenvalues D:’);
disp(d);
end I’m following this documentation: Model an Excavator Dipper Arm as a Flexible Body – MATLAB & Simulink (mathworks.com).
I copied the entire code and it works with the Dipper.STL file, but for every other STL file i import, I get the ‘zero eigenvalue" error mentioned in the title. The simplest STL file I used was a cube modeled in spaceclaim (10 x 10 x 60 mm). I’ve varied the mesh fineness to be on a spectrum similar to the dipper arm.
I’ve looked at all settings and not figured out what might be wrong. I also added a fixed support for the first frame; didn’t make a difference. It’s also worthy noting that the stiffness matrix seemed to have non-zero values just the first few rows, but the rest seemd to be absolutely zero. Here’s the entire thing.
clear
clc
cd(‘G:My DriveStudiesM.Sc. Mechanical Engineering24 SMMatlabBeam_Atli’)
stlFile = ‘beam_Atli2.stl’;
figure
trisurf(stlread(stlFile))
axis equal
E = 10e9; % Young’s modulus in Pa
nu = 0.26; % Poisson’s ratio (nondimensional)
rho = 7800; % Mass density in kg/m^3
origins = [60 0.5 -5 % Frame 1: Cylinder connection point
30 0.5 0 % Frame 2: Bucket connection point
0 0.5 -5]; % Frame 3: Fulcrum point
numFrames = size(origins,1);
feModel = createpde(‘structural’,’modal-solid’);
importGeometry(feModel,stlFile);
structuralProperties(feModel, …
‘YoungsModulus’,E, …
‘PoissonsRatio’,nu, …
‘MassDensity’,rho);
generateMesh(feModel, …
‘GeometricOrder’,’quadratic’, …
‘Hmax’,2.5, …
‘Hmin’,0.25);
figure
pdegplot(feModel,’FaceLabels’,’on’,’FaceAlpha’,0.5)
faceIDs = [1,2,3]; % List in the same order as the interface frame origins
figure
pdemesh(feModel,’FaceAlpha’,0.5)
hold on
colors = [‘rgb’ repmat(‘k’,1,numFrames-3)];
assert(numel(faceIDs) == numFrames);
for k = 1:numFrames
nodeIdxs = findNodes(feModel.Mesh,’region’,’Face’,faceIDs(k));
scatter3( …
feModel.Mesh.Nodes(1,nodeIdxs), …
feModel.Mesh.Nodes(2,nodeIdxs), …
feModel.Mesh.Nodes(3,nodeIdxs), …
‘ok’,’MarkerFaceColor’,colors(k))
scatter3( …
origins(k,1), …
origins(k,2), …
origins(k,3), …
80,colors(k),’filled’,’s’)
end
hold off
structuralBC(feModel, ‘Face’, faceIDs(1), ‘Constraint’, ‘fixed’);
for k = 1:numFrames
structuralBC(feModel, …
‘Face’,faceIDs(k), …
‘Constraint’,’multipoint’, …
‘Reference’,origins(k,:));
end
rom = reduce(feModel,’FrequencyRange’,[0 1e4]);
arm.P = rom.ReferenceLocations’; % Interface frame locations (n x 3 matrix)
arm.K = rom.K; % Reduced stiffness matrix
arm.M = rom.M; % Reduced mass matrix
dampingRatio = 0.05;
arm.C = computeModalDampingMatrix(dampingRatio,rom.K,rom.M);
frmPerm = zeros(numFrames,1); % Frame permutation vector
dofPerm = 1:size(arm.K,1); % DOF permutation vector
assert(size(arm.P,1) == numFrames);
for i = 1:numFrames
for j = 1:numFrames
if isequal(arm.P(j,:),origins(i,:))
frmPerm(i) = j;
dofPerm(6*(i-1)+(1:6)) = 6*(j-1)+(1:6);
continue;
end
end
end
assert(numel(frmPerm) == numFrames);
assert(numel(dofPerm) == size(arm.K,1));
arm.P = arm.P(frmPerm,:);
arm.K = arm.K(dofPerm,:);
arm.K = arm.K(:,dofPerm);
arm.M = arm.M(dofPerm,:);
arm.M = arm.M(:,dofPerm);
arm.C = arm.C(dofPerm,:);
arm.C = arm.C(:,dofPerm);
function C = computeModalDampingMatrix(dampingRatio,K,M)
% To avoid numerical issues (such as complex eigenvalues with very small
% imaginary parts), make the matrices exactly symmetric.
K = (K+K’)/2; % Stiffness matrix
M = (M+M’)/2; % Mass matrix
% Compute the eigen-decomposition associated with the mass and stiffness
% matrices, sorting the eigenvalues in ascending order and permuting
% the corresponding eigenvectors.
[V,D] = eig(K,M);
[d,sortIdxs] = sort(diag(D));
V = V(:,sortIdxs);
% Due to small numerical errors, the six eigenvalues associated with the
% rigid-body modes may not be exactly zero. To avoid numerical issues,
% check that the first six eigenvalues are close enough to zero. Then
% replace them with exact 0 values.
assert(all(abs(d(1:6))/abs(d(7)) < 1e-9),’Error due to "zero" eigenvalues.’);
d(1:6) = 0;
% Vectors of generalized masses and natural frequencies
MV = M*V;
generalizedMasses = diag(V’*MV);
naturalFrequencies = sqrt(d);
% Compute the modal damping matrix associated with K and M
C = MV * diag(2*dampingRatio*naturalFrequencies./generalizedMasses) * MV’;
% Print the eigenmodes
disp(‘Eigenmodes (eigenvectors) V:’);
disp(V);
disp(‘Eigenvalues D:’);
disp(d);
end matlab, simulink, stl, error, eigenvalue, flexible MATLAB Answers — New Questions