Tag Archives: matlab
Error in ode45 (line 107)
Hello, I’m trying to model the biomass accumulation over time of a microorganism that depends on temperature using a differential equation that I want to solve with ode45 function. But I got this error message:
Error using odearguments
@(TIME,XI)DXDT(TIME,XI,TEMP,PARAM,PARAM_PH,PH) returns a vector of length 29613, but the length of initial conditions vector is 1. The vector returned by
@(TIME,XI)DXDT(TIME,XI,TEMP,PARAM,PARAM_PH,PH) and the initial conditions vector must have the same number of elements.
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
After checking, I figured out that the ode45 function doesn’t take my temperature vector but only one cell of it (knowing that the size of my temperature and time vectors is the same).
Can you help me out to solve this issue please?
Here is my code for ode45:
tspan = Time; %Time vector with the same length as experimental data
%C0 is the initial biomass concentration
%the vector param contains my parameters [tmin,topt,tmax,mumax]
[t,xi] = ode45(@(t,xi) dxdt(t,xi,temperature,param),tspan,C0, odeset(‘RelTol’,1E-3));
Here is my dfunction to calculate the ifferential equation:
function dC=dxdt(t,C,Temp,param,param_ph,pH)
dC=C.*phi(param,Temp);
end
Thanks in advance for you help :)Hello, I’m trying to model the biomass accumulation over time of a microorganism that depends on temperature using a differential equation that I want to solve with ode45 function. But I got this error message:
Error using odearguments
@(TIME,XI)DXDT(TIME,XI,TEMP,PARAM,PARAM_PH,PH) returns a vector of length 29613, but the length of initial conditions vector is 1. The vector returned by
@(TIME,XI)DXDT(TIME,XI,TEMP,PARAM,PARAM_PH,PH) and the initial conditions vector must have the same number of elements.
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
After checking, I figured out that the ode45 function doesn’t take my temperature vector but only one cell of it (knowing that the size of my temperature and time vectors is the same).
Can you help me out to solve this issue please?
Here is my code for ode45:
tspan = Time; %Time vector with the same length as experimental data
%C0 is the initial biomass concentration
%the vector param contains my parameters [tmin,topt,tmax,mumax]
[t,xi] = ode45(@(t,xi) dxdt(t,xi,temperature,param),tspan,C0, odeset(‘RelTol’,1E-3));
Here is my dfunction to calculate the ifferential equation:
function dC=dxdt(t,C,Temp,param,param_ph,pH)
dC=C.*phi(param,Temp);
end
Thanks in advance for you help 🙂 Hello, I’m trying to model the biomass accumulation over time of a microorganism that depends on temperature using a differential equation that I want to solve with ode45 function. But I got this error message:
Error using odearguments
@(TIME,XI)DXDT(TIME,XI,TEMP,PARAM,PARAM_PH,PH) returns a vector of length 29613, but the length of initial conditions vector is 1. The vector returned by
@(TIME,XI)DXDT(TIME,XI,TEMP,PARAM,PARAM_PH,PH) and the initial conditions vector must have the same number of elements.
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
After checking, I figured out that the ode45 function doesn’t take my temperature vector but only one cell of it (knowing that the size of my temperature and time vectors is the same).
Can you help me out to solve this issue please?
Here is my code for ode45:
tspan = Time; %Time vector with the same length as experimental data
%C0 is the initial biomass concentration
%the vector param contains my parameters [tmin,topt,tmax,mumax]
[t,xi] = ode45(@(t,xi) dxdt(t,xi,temperature,param),tspan,C0, odeset(‘RelTol’,1E-3));
Here is my dfunction to calculate the ifferential equation:
function dC=dxdt(t,C,Temp,param,param_ph,pH)
dC=C.*phi(param,Temp);
end
Thanks in advance for you help 🙂 error in ode45 (line 107) MATLAB Answers — New Questions
Error using open ep/requirement/al/keys/RequirementsSourceKey whey lauching Simulink Project
Hello,
I got an ‘Error using open ep/requirement/al/keys/RequirementsSourceKey" when I launch the Simulink Project. This error appears irregularily and I don’t know what causes it and it means !
Does any one know about it ?
With advance thanks !
Riad Boukhari.Hello,
I got an ‘Error using open ep/requirement/al/keys/RequirementsSourceKey" when I launch the Simulink Project. This error appears irregularily and I don’t know what causes it and it means !
Does any one know about it ?
With advance thanks !
Riad Boukhari. Hello,
I got an ‘Error using open ep/requirement/al/keys/RequirementsSourceKey" when I launch the Simulink Project. This error appears irregularily and I don’t know what causes it and it means !
Does any one know about it ?
With advance thanks !
Riad Boukhari. simulink, simulink project, matlab 2022b MATLAB Answers — New Questions
my license for database toolbox isn’t linked to mobile Matlab
I have bought the license of Database Toolbox and it wotks fine in Mac. When I try to connect with an sqlite .db file in the iPad Pro, I got an error message ‘require Database Toolbox require’.
I contacted Mathworks suppirt, but it was Terasoft Tech Support that responded (I don’t understand why that happened). They suggested me to link my license with my Mathworks user account, but I already did. Mobile Matlab in my iPad Pro still require the toolbox. What have I been missing?I have bought the license of Database Toolbox and it wotks fine in Mac. When I try to connect with an sqlite .db file in the iPad Pro, I got an error message ‘require Database Toolbox require’.
I contacted Mathworks suppirt, but it was Terasoft Tech Support that responded (I don’t understand why that happened). They suggested me to link my license with my Mathworks user account, but I already did. Mobile Matlab in my iPad Pro still require the toolbox. What have I been missing? I have bought the license of Database Toolbox and it wotks fine in Mac. When I try to connect with an sqlite .db file in the iPad Pro, I got an error message ‘require Database Toolbox require’.
I contacted Mathworks suppirt, but it was Terasoft Tech Support that responded (I don’t understand why that happened). They suggested me to link my license with my Mathworks user account, but I already did. Mobile Matlab in my iPad Pro still require the toolbox. What have I been missing? database toolbox, mobile matlab, license MATLAB Answers — New Questions
Converting NumericEditFields to TextEditFields in App Designer
Is there an easy way to convert NumericEditField components to TextEditField components in Appdesigner? Unfortunately, "Replace with" does not give that as an option. I have 42 of them that I would like to convert [to TextEditField] so that users can type in executable commands instead of having to type numeric values. As one can imagine, creating "new" TextEditFields" to replace numeric ones would be a nightmare. Thank you in advance [even if the short answer is "no"]…Is there an easy way to convert NumericEditField components to TextEditField components in Appdesigner? Unfortunately, "Replace with" does not give that as an option. I have 42 of them that I would like to convert [to TextEditField] so that users can type in executable commands instead of having to type numeric values. As one can imagine, creating "new" TextEditFields" to replace numeric ones would be a nightmare. Thank you in advance [even if the short answer is "no"]… Is there an easy way to convert NumericEditField components to TextEditField components in Appdesigner? Unfortunately, "Replace with" does not give that as an option. I have 42 of them that I would like to convert [to TextEditField] so that users can type in executable commands instead of having to type numeric values. As one can imagine, creating "new" TextEditFields" to replace numeric ones would be a nightmare. Thank you in advance [even if the short answer is "no"]… numericeditfield to texteditfield, appdesigner MATLAB Answers — New Questions
Generate Equations of Motion of Simscape Model
Hi all,
Are the equations of motion formulated by MATLAB Simscape Multibody available to the users? From what I understand, the equations are generated internally and cannot be extracted by the users. But I want to be sure on this.
I also tried using the C code generation but it numerically integrates the equations and doesn’t give access to the equations directly.
Any comments are appreciated. Thanks!Hi all,
Are the equations of motion formulated by MATLAB Simscape Multibody available to the users? From what I understand, the equations are generated internally and cannot be extracted by the users. But I want to be sure on this.
I also tried using the C code generation but it numerically integrates the equations and doesn’t give access to the equations directly.
Any comments are appreciated. Thanks! Hi all,
Are the equations of motion formulated by MATLAB Simscape Multibody available to the users? From what I understand, the equations are generated internally and cannot be extracted by the users. But I want to be sure on this.
I also tried using the C code generation but it numerically integrates the equations and doesn’t give access to the equations directly.
Any comments are appreciated. Thanks! simscape, differential equations, equations of motion, code generation MATLAB Answers — New Questions
Contour Plot Issue – Is the data shown correctly?
Code does the following: Given 3 mic locations and a source S location, it calculates the intersection points from any location in the x-y plane with a circle centered at the mic locations with radius as the distance between the mic and the source.
The distance between the respective intersection points are calculated and added together. So at the source location, the total distance is approximately zero.
The contour plot is meant to plot the total added distance(‘nt’ in the code) against the X-Y plane. I am not sure if I am plotting it correctly. The contour plot doesn’t seem to change shape with change of the source location and that is not right. I checked at the source location if Z1 = Z2 = Z3 and they do. I am not sure if I am plotting incorrectly.
The code should run smoothly – all the functions I created are at the very end of the code.
clear;clc; %Clearing Variables
%% Creating Data
% defining locations
S = [ 0 40 0 ]; %source location [x y z]
M1 =[10 0 0];% Mic 1 location
M2 = [20 0 0];%Mic 2
M3 =[30 0 0]; %Mic 3
% Plane
a = -50;
b = 50;
x = a:b;
y = (a:b).’;
v = numel(x);
%% Calculations
%distance calculated for x-y plane
r1 = normal(S(1,1),M1(1,1),S(1,2),M1(1,2));
r2 = normal(S(1,1),M2(1,1),S(1,2),M2(1,2));
r3 = normal(S(1,1),M3(1,1),S(1,2),M3(1,2));
% Getting the intersection points
Z1 =intersect2(x,y,M1(1),M1(2),r1);
Z2=intersect2(x,y,M2(1),M2(2),r2);
Z3=intersect2(x,y,M3(1),M3(2),r3);
% Calculating the distance between intersection points
[A,~]= size(Z1);
n1 = zeros(A,1);
n2 = zeros(A,1);
n3 = zeros(A,1);
for i = 1:A
n1(i) = norm(Z2(i)-Z1(i));
n2(i) = norm(Z3(i)-Z2(i));
n3(i) = norm(Z1(i)-Z3(i));
end
%total distance for each set of intersection points
nt = n1 + n2 + n3;
%% PLOTTING
%making circles
%for x-y plane
[xm1,ym1] = circle(M1(1,1),M1(1,2),r1);
[xm2,ym2] = circle(M2(1,1),M2(1,2),r2);
[xm3,ym3] = circle(M3(1,1),M3(1,2),r3);
% % %for the x-y plane
%
[X, Y]= ndgrid(x,x);
ZZ = [X(:) , Y(:)];
X = reshape(ZZ(:,1),[v,v]);
Y = reshape(ZZ(:,2),[v,v]);
Z = reshape(nt,[v,v]);
plot(xm1,ym1,’k’)
hold on
plot(M1(1),M1(2),’ks’)
hold on
plot(xm2,ym2,’r’)
plot(M2(1),M2(2),’rs’)
plot(xm3,ym3,’g’)
plot(M3(1),M3(2),’gs’)
plot(S(1),S(2),’ks’)
contour(X,Y,Z,30,’ShowText’,’off’)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [xunit, yunit] = circle(x,y,r)
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
hold off
end
function d = normal(x1,x2,y1,y2)
d = sqrt((x2-x1).^2+(y2-y1).^2);
end
function [Z] = intersect2(x,y,cx,cy,r)
%calculates the intersection points of a line and a circle
u = numel(x);
Z = zeros(u*u,2);
% x = -a:b;
% y = (-a:b).’;
theta = atan2((y-cy) ,(x-cx));
% chk = r* sin(theta)
Zx = cx + r*cos(theta);
Zy = cy + r*sin(theta);
Z = [Zx(:) Zy(:)];
endCode does the following: Given 3 mic locations and a source S location, it calculates the intersection points from any location in the x-y plane with a circle centered at the mic locations with radius as the distance between the mic and the source.
The distance between the respective intersection points are calculated and added together. So at the source location, the total distance is approximately zero.
The contour plot is meant to plot the total added distance(‘nt’ in the code) against the X-Y plane. I am not sure if I am plotting it correctly. The contour plot doesn’t seem to change shape with change of the source location and that is not right. I checked at the source location if Z1 = Z2 = Z3 and they do. I am not sure if I am plotting incorrectly.
The code should run smoothly – all the functions I created are at the very end of the code.
clear;clc; %Clearing Variables
%% Creating Data
% defining locations
S = [ 0 40 0 ]; %source location [x y z]
M1 =[10 0 0];% Mic 1 location
M2 = [20 0 0];%Mic 2
M3 =[30 0 0]; %Mic 3
% Plane
a = -50;
b = 50;
x = a:b;
y = (a:b).’;
v = numel(x);
%% Calculations
%distance calculated for x-y plane
r1 = normal(S(1,1),M1(1,1),S(1,2),M1(1,2));
r2 = normal(S(1,1),M2(1,1),S(1,2),M2(1,2));
r3 = normal(S(1,1),M3(1,1),S(1,2),M3(1,2));
% Getting the intersection points
Z1 =intersect2(x,y,M1(1),M1(2),r1);
Z2=intersect2(x,y,M2(1),M2(2),r2);
Z3=intersect2(x,y,M3(1),M3(2),r3);
% Calculating the distance between intersection points
[A,~]= size(Z1);
n1 = zeros(A,1);
n2 = zeros(A,1);
n3 = zeros(A,1);
for i = 1:A
n1(i) = norm(Z2(i)-Z1(i));
n2(i) = norm(Z3(i)-Z2(i));
n3(i) = norm(Z1(i)-Z3(i));
end
%total distance for each set of intersection points
nt = n1 + n2 + n3;
%% PLOTTING
%making circles
%for x-y plane
[xm1,ym1] = circle(M1(1,1),M1(1,2),r1);
[xm2,ym2] = circle(M2(1,1),M2(1,2),r2);
[xm3,ym3] = circle(M3(1,1),M3(1,2),r3);
% % %for the x-y plane
%
[X, Y]= ndgrid(x,x);
ZZ = [X(:) , Y(:)];
X = reshape(ZZ(:,1),[v,v]);
Y = reshape(ZZ(:,2),[v,v]);
Z = reshape(nt,[v,v]);
plot(xm1,ym1,’k’)
hold on
plot(M1(1),M1(2),’ks’)
hold on
plot(xm2,ym2,’r’)
plot(M2(1),M2(2),’rs’)
plot(xm3,ym3,’g’)
plot(M3(1),M3(2),’gs’)
plot(S(1),S(2),’ks’)
contour(X,Y,Z,30,’ShowText’,’off’)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [xunit, yunit] = circle(x,y,r)
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
hold off
end
function d = normal(x1,x2,y1,y2)
d = sqrt((x2-x1).^2+(y2-y1).^2);
end
function [Z] = intersect2(x,y,cx,cy,r)
%calculates the intersection points of a line and a circle
u = numel(x);
Z = zeros(u*u,2);
% x = -a:b;
% y = (-a:b).’;
theta = atan2((y-cy) ,(x-cx));
% chk = r* sin(theta)
Zx = cx + r*cos(theta);
Zy = cy + r*sin(theta);
Z = [Zx(:) Zy(:)];
end Code does the following: Given 3 mic locations and a source S location, it calculates the intersection points from any location in the x-y plane with a circle centered at the mic locations with radius as the distance between the mic and the source.
The distance between the respective intersection points are calculated and added together. So at the source location, the total distance is approximately zero.
The contour plot is meant to plot the total added distance(‘nt’ in the code) against the X-Y plane. I am not sure if I am plotting it correctly. The contour plot doesn’t seem to change shape with change of the source location and that is not right. I checked at the source location if Z1 = Z2 = Z3 and they do. I am not sure if I am plotting incorrectly.
The code should run smoothly – all the functions I created are at the very end of the code.
clear;clc; %Clearing Variables
%% Creating Data
% defining locations
S = [ 0 40 0 ]; %source location [x y z]
M1 =[10 0 0];% Mic 1 location
M2 = [20 0 0];%Mic 2
M3 =[30 0 0]; %Mic 3
% Plane
a = -50;
b = 50;
x = a:b;
y = (a:b).’;
v = numel(x);
%% Calculations
%distance calculated for x-y plane
r1 = normal(S(1,1),M1(1,1),S(1,2),M1(1,2));
r2 = normal(S(1,1),M2(1,1),S(1,2),M2(1,2));
r3 = normal(S(1,1),M3(1,1),S(1,2),M3(1,2));
% Getting the intersection points
Z1 =intersect2(x,y,M1(1),M1(2),r1);
Z2=intersect2(x,y,M2(1),M2(2),r2);
Z3=intersect2(x,y,M3(1),M3(2),r3);
% Calculating the distance between intersection points
[A,~]= size(Z1);
n1 = zeros(A,1);
n2 = zeros(A,1);
n3 = zeros(A,1);
for i = 1:A
n1(i) = norm(Z2(i)-Z1(i));
n2(i) = norm(Z3(i)-Z2(i));
n3(i) = norm(Z1(i)-Z3(i));
end
%total distance for each set of intersection points
nt = n1 + n2 + n3;
%% PLOTTING
%making circles
%for x-y plane
[xm1,ym1] = circle(M1(1,1),M1(1,2),r1);
[xm2,ym2] = circle(M2(1,1),M2(1,2),r2);
[xm3,ym3] = circle(M3(1,1),M3(1,2),r3);
% % %for the x-y plane
%
[X, Y]= ndgrid(x,x);
ZZ = [X(:) , Y(:)];
X = reshape(ZZ(:,1),[v,v]);
Y = reshape(ZZ(:,2),[v,v]);
Z = reshape(nt,[v,v]);
plot(xm1,ym1,’k’)
hold on
plot(M1(1),M1(2),’ks’)
hold on
plot(xm2,ym2,’r’)
plot(M2(1),M2(2),’rs’)
plot(xm3,ym3,’g’)
plot(M3(1),M3(2),’gs’)
plot(S(1),S(2),’ks’)
contour(X,Y,Z,30,’ShowText’,’off’)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [xunit, yunit] = circle(x,y,r)
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
hold off
end
function d = normal(x1,x2,y1,y2)
d = sqrt((x2-x1).^2+(y2-y1).^2);
end
function [Z] = intersect2(x,y,cx,cy,r)
%calculates the intersection points of a line and a circle
u = numel(x);
Z = zeros(u*u,2);
% x = -a:b;
% y = (-a:b).’;
theta = atan2((y-cy) ,(x-cx));
% chk = r* sin(theta)
Zx = cx + r*cos(theta);
Zy = cy + r*sin(theta);
Z = [Zx(:) Zy(:)];
end contour, plot, data, time of flight, numerical calculation, matlab MATLAB Answers — New Questions
How can I extract real time data (.csv or .text format) from my Simulink file running in simulink desktop real time?
I started using simulink desktop real time recently and developed battery management system in real time. My objective is to run my BMS model in a dedicated single board comupter in simulink desktop real time mode and process the BMS real time data (in .text file or .csv file.) in an external hardware controller. Please let me know how to extract the data from simulink desktop real time?I started using simulink desktop real time recently and developed battery management system in real time. My objective is to run my BMS model in a dedicated single board comupter in simulink desktop real time mode and process the BMS real time data (in .text file or .csv file.) in an external hardware controller. Please let me know how to extract the data from simulink desktop real time? I started using simulink desktop real time recently and developed battery management system in real time. My objective is to run my BMS model in a dedicated single board comupter in simulink desktop real time mode and process the BMS real time data (in .text file or .csv file.) in an external hardware controller. Please let me know how to extract the data from simulink desktop real time? simulink desktop real time data extraction MATLAB Answers — New Questions
How to apply a time decaying internal heat source?
Hi
I’m trying to model the decay of nuclear fuel following an accident, I need to be able to apply an equation for the decay heat produced by the fuel to the internal heat source of the model.
This is my current code with P being the equation that should represent the decay heat.
thermalmodel= createpde(‘thermal’,"transient");
gm = multicylinder([4.655e-3 4.865e-3 5.59e-3],12.6e-3);
thermalmodel.Geometry = gm;
pdegplot(thermalmodel, "CellLabels",’on’,’FaceLabels’,’on’,"FaceAlpha",0.2);
thermalProperties(thermalmodel,’Cell’,1,’ThermalConductivity’,7,"MassDensity",10.97, "SpecificHeat",370); % Uranium
thermalProperties(thermalmodel,’Cell’,2,’ThermalConductivity’,252.48e-3 ,"MassDensity",0.178e-3,"SpecificHeat",5.193); % Helium
thermalProperties(thermalmodel,’Cell’,3,’ThermalConductivity’, 21.5,"MassDensity",6.55,"SpecificHeat",0.328); % Zircalloy
tlist = (10:1:100);
for a = 1 : length(tlist)
P(a) = 100e6*0.066*((tlist(a).^(-0.2))- ((10*24*60*60)+tlist(a)).^(-0.2));
end
internalHeatSource(thermalmodel,P,"Cell",1);
thermalIC(thermalmodel,873);
generateMesh(thermalmodel);
pdemesh(thermalmodel);
tic
thermalresults = solve(thermalmodel,tlist);
toc
Tcenter = interpolateTemperature(thermalresults,0,0,0,1:numel(tlist))
plot(tlist,Tcenter)Hi
I’m trying to model the decay of nuclear fuel following an accident, I need to be able to apply an equation for the decay heat produced by the fuel to the internal heat source of the model.
This is my current code with P being the equation that should represent the decay heat.
thermalmodel= createpde(‘thermal’,"transient");
gm = multicylinder([4.655e-3 4.865e-3 5.59e-3],12.6e-3);
thermalmodel.Geometry = gm;
pdegplot(thermalmodel, "CellLabels",’on’,’FaceLabels’,’on’,"FaceAlpha",0.2);
thermalProperties(thermalmodel,’Cell’,1,’ThermalConductivity’,7,"MassDensity",10.97, "SpecificHeat",370); % Uranium
thermalProperties(thermalmodel,’Cell’,2,’ThermalConductivity’,252.48e-3 ,"MassDensity",0.178e-3,"SpecificHeat",5.193); % Helium
thermalProperties(thermalmodel,’Cell’,3,’ThermalConductivity’, 21.5,"MassDensity",6.55,"SpecificHeat",0.328); % Zircalloy
tlist = (10:1:100);
for a = 1 : length(tlist)
P(a) = 100e6*0.066*((tlist(a).^(-0.2))- ((10*24*60*60)+tlist(a)).^(-0.2));
end
internalHeatSource(thermalmodel,P,"Cell",1);
thermalIC(thermalmodel,873);
generateMesh(thermalmodel);
pdemesh(thermalmodel);
tic
thermalresults = solve(thermalmodel,tlist);
toc
Tcenter = interpolateTemperature(thermalresults,0,0,0,1:numel(tlist))
plot(tlist,Tcenter) Hi
I’m trying to model the decay of nuclear fuel following an accident, I need to be able to apply an equation for the decay heat produced by the fuel to the internal heat source of the model.
This is my current code with P being the equation that should represent the decay heat.
thermalmodel= createpde(‘thermal’,"transient");
gm = multicylinder([4.655e-3 4.865e-3 5.59e-3],12.6e-3);
thermalmodel.Geometry = gm;
pdegplot(thermalmodel, "CellLabels",’on’,’FaceLabels’,’on’,"FaceAlpha",0.2);
thermalProperties(thermalmodel,’Cell’,1,’ThermalConductivity’,7,"MassDensity",10.97, "SpecificHeat",370); % Uranium
thermalProperties(thermalmodel,’Cell’,2,’ThermalConductivity’,252.48e-3 ,"MassDensity",0.178e-3,"SpecificHeat",5.193); % Helium
thermalProperties(thermalmodel,’Cell’,3,’ThermalConductivity’, 21.5,"MassDensity",6.55,"SpecificHeat",0.328); % Zircalloy
tlist = (10:1:100);
for a = 1 : length(tlist)
P(a) = 100e6*0.066*((tlist(a).^(-0.2))- ((10*24*60*60)+tlist(a)).^(-0.2));
end
internalHeatSource(thermalmodel,P,"Cell",1);
thermalIC(thermalmodel,873);
generateMesh(thermalmodel);
pdemesh(thermalmodel);
tic
thermalresults = solve(thermalmodel,tlist);
toc
Tcenter = interpolateTemperature(thermalresults,0,0,0,1:numel(tlist))
plot(tlist,Tcenter) pde toolbox, internal heat source MATLAB Answers — New Questions
PDE HEAT WAVE EQUATIONP
1) Solve the PDE utt = 4uxx on 0 < x < π, 0 < t, with BC: u(0, t) = u(π, t) = 0 IC: u(x, 0) = sin(2x), ∂u(x, 0) ∂t = 01) Solve the PDE utt = 4uxx on 0 < x < π, 0 < t, with BC: u(0, t) = u(π, t) = 0 IC: u(x, 0) = sin(2x), ∂u(x, 0) ∂t = 0 1) Solve the PDE utt = 4uxx on 0 < x < π, 0 < t, with BC: u(0, t) = u(π, t) = 0 IC: u(x, 0) = sin(2x), ∂u(x, 0) ∂t = 0 pde MATLAB Answers — New Questions
Using n-D Look Up Tables for Data Conversion
Hello Everyone!
I hope you all are doing well! For a real time experiement I am trying to run in Simulink, I am trying to figure out a way to convert data from 8 different EMG sensors and stream them into tabular form in order to use a Classification Leaner function to make live predictions of this data. I am envisioning a table within Simulink that has 8 columns, each for the 8 different sensors, with rows representing the time stamps of the data values across the different sensors of data. The rows should be constantly increasing throughout the experiment.
I am trying to us an 8-D Look-Up table in order to join the 8 different data streams into tabular form, but I cannot figure out how to shape the parameters of the table (the breakpoints and tabular data settings specifically). Can someone help me with this, or suggest an easier alternative to accomplish what I am thiniking of?
Thanks in advance!Hello Everyone!
I hope you all are doing well! For a real time experiement I am trying to run in Simulink, I am trying to figure out a way to convert data from 8 different EMG sensors and stream them into tabular form in order to use a Classification Leaner function to make live predictions of this data. I am envisioning a table within Simulink that has 8 columns, each for the 8 different sensors, with rows representing the time stamps of the data values across the different sensors of data. The rows should be constantly increasing throughout the experiment.
I am trying to us an 8-D Look-Up table in order to join the 8 different data streams into tabular form, but I cannot figure out how to shape the parameters of the table (the breakpoints and tabular data settings specifically). Can someone help me with this, or suggest an easier alternative to accomplish what I am thiniking of?
Thanks in advance! Hello Everyone!
I hope you all are doing well! For a real time experiement I am trying to run in Simulink, I am trying to figure out a way to convert data from 8 different EMG sensors and stream them into tabular form in order to use a Classification Leaner function to make live predictions of this data. I am envisioning a table within Simulink that has 8 columns, each for the 8 different sensors, with rows representing the time stamps of the data values across the different sensors of data. The rows should be constantly increasing throughout the experiment.
I am trying to us an 8-D Look-Up table in order to join the 8 different data streams into tabular form, but I cannot figure out how to shape the parameters of the table (the breakpoints and tabular data settings specifically). Can someone help me with this, or suggest an easier alternative to accomplish what I am thiniking of?
Thanks in advance! simulink, real time data, lookup table, data acquisition MATLAB Answers — New Questions
Tracing signals in script
I am trying to "trace" signals through a model, from the outports back to the inports. My script will go into a subsystem in the model, however, when it gets to the inports in that subsystem, I do not know how to find the corresponding signal/source block from the level above. Can anyone provide some help on how to do this? To trace into the subsystem, I am using:
subhandle = find_system(handle, ‘LookUnderMasks’, ‘all’, ‘FollowLinks’, ‘on’, ‘SearchDepth’, 1, ‘BlockType’, ‘Outport’);
Perhaps there is something similar to use to get back up a level?
I am also having trouble finding a matching GoTo block when I get to a From block, so any help would be appreciated. ThanksI am trying to "trace" signals through a model, from the outports back to the inports. My script will go into a subsystem in the model, however, when it gets to the inports in that subsystem, I do not know how to find the corresponding signal/source block from the level above. Can anyone provide some help on how to do this? To trace into the subsystem, I am using:
subhandle = find_system(handle, ‘LookUnderMasks’, ‘all’, ‘FollowLinks’, ‘on’, ‘SearchDepth’, 1, ‘BlockType’, ‘Outport’);
Perhaps there is something similar to use to get back up a level?
I am also having trouble finding a matching GoTo block when I get to a From block, so any help would be appreciated. Thanks I am trying to "trace" signals through a model, from the outports back to the inports. My script will go into a subsystem in the model, however, when it gets to the inports in that subsystem, I do not know how to find the corresponding signal/source block from the level above. Can anyone provide some help on how to do this? To trace into the subsystem, I am using:
subhandle = find_system(handle, ‘LookUnderMasks’, ‘all’, ‘FollowLinks’, ‘on’, ‘SearchDepth’, 1, ‘BlockType’, ‘Outport’);
Perhaps there is something similar to use to get back up a level?
I am also having trouble finding a matching GoTo block when I get to a From block, so any help would be appreciated. Thanks script MATLAB Answers — New Questions
Can you stream and record cycling data such as power and cadence from Garmin TACX trainer using ANT+ dongle?
Hi,
I have googled it, but I am still unsure what toolbox I need and if it is feasible. I am looking for a way to stream and record cycling data measured by Garmin TACX trainer using ANT+ dongle. Also, I was wondering if the target power output can be controlled in MATLAB as well. Any advice and suggestions are appreciated.Hi,
I have googled it, but I am still unsure what toolbox I need and if it is feasible. I am looking for a way to stream and record cycling data measured by Garmin TACX trainer using ANT+ dongle. Also, I was wondering if the target power output can be controlled in MATLAB as well. Any advice and suggestions are appreciated. Hi,
I have googled it, but I am still unsure what toolbox I need and if it is feasible. I am looking for a way to stream and record cycling data measured by Garmin TACX trainer using ANT+ dongle. Also, I was wondering if the target power output can be controlled in MATLAB as well. Any advice and suggestions are appreciated. ant+ MATLAB Answers — New Questions
Invalid argument “simscapeelectricalsps”.
>> openExample(‘simscapeelectricalsps/SinglePhaseASMExample’)
while I got an error shows as following
please tell me what is causing this problem? or which toolbox is lack?
And how can I find all the toolboxes needed for examples?>> openExample(‘simscapeelectricalsps/SinglePhaseASMExample’)
while I got an error shows as following
please tell me what is causing this problem? or which toolbox is lack?
And how can I find all the toolboxes needed for examples? >> openExample(‘simscapeelectricalsps/SinglePhaseASMExample’)
while I got an error shows as following
please tell me what is causing this problem? or which toolbox is lack?
And how can I find all the toolboxes needed for examples? openexample, toolbox MATLAB Answers — New Questions
How to create Architecture model and paste the Reference example of Vehicle dynamics double lane change.
Post Content Post Content v-model, vehicle dynamics, architecture MATLAB Answers — New Questions
Population Growth Model Analysis
Below I tried to solve Population Growth problem, I provide you the mathematical solution. Also, I create MATLAB code, however i feel like that i repeat this code to each part of this code as you can see. How could I improve this code?
Assume a continuous growth model where the function that gives the rate of change is defined as . Provide the function , which represents the population size.
If the growth of a population follows the logistic law but there is also a term for population reduction (e.g., from a predator while the members of the population are the prey), the equation that expresses the population size is of the form
where the term is given here to be and it represents a term for population reduction. The constants are positive. Normalize the equation by setting and .Find the steady solutions of the problem (real and positive) and then implement a program in MATLAB to numerically solve the dimensionless form of the equation. Make the graphical representation of the numerical solution for , with initial conditions , and respectively. What do you observe?
So we have
We are going to find the function :
To find , we integrate :
where is the integration constant, which can be determined if an initial condition is given, such as .
Now we are going to normalize the equation:
Let and . Then:
We substitute into the original equation:
Then we are going to calculate the Stationary Points:
Set :
]
For :
% Define the normalized logistic equation with reduction term
% K/a = 35, ar/b = 0.4
Ka = 35;
ar_b = 0.4;
% Define the function for the normalized logistic equation
f = @(tau, N) ar_b * N * (1 – N/Ka) – N / (1 + N);
% Time span for the simulation
tspan = [0 50]; % Adjust if needed to observe long-term behavior
% Initial conditions
N0 = [40, 25, 2, 0.05];
% Prepare the figure for plotting
figure(1);
hold on;
% Colors for different trajectories
colors = [‘r’, ‘g’, ‘b’, ‘k’]; % Red, Green, Blue, Black
% Solve the equation for each initial condition and plot
for i = 1:length(N0)
[T, N] = ode45(f, tspan, N0(i));
plot(T, N, ‘Color’, colors(i), ‘LineWidth’, 2);
legendInfo{i} = [‘N_0 = ‘ num2str(N0(i))]; % Create legend entry
end
% Add graph details
title(‘Numerical solutions of the normalized logistic equation’);
xlabel(‘Normalized time τ’);
ylabel(‘Normalized population size N’);
legend(legendInfo, ‘Location’, ‘northeastoutside’);
grid on;
hold off;
% Equilibrium analysis
syms N
eqn = ar_b * N * (1 – N / Ka) – N / (1 + N) == 0;
equilibria = double(solve(eqn, N));
% Stability analysis
f = @(N) ar_b * N * (1 – N / Ka) – N / (1 + N);
J = diff(f(N), N);
eigenvalues = double(subs(J, N, equilibria));
disp(‘Equilibrium Points and their Stability:’);
for i = 1:length(equilibria)
if real(eigenvalues(i)) < 0
stability = ‘Stable’;
else
stability = ‘Unstable’;
end
fprintf(‘N = %f: Eigenvalue = %f, %sn’, equilibria(i), eigenvalues(i), stability);
end
% Bifurcation analysis setup
ar_b_values = linspace(0.1, 1, 100);
bifurcation_results = zeros(length(ar_b_values), 10); % Adjust the columns based on expected number of roots
% Compute equilibrium points for varying ar/b
for i = 1:length(ar_b_values)
eqn = ar_b_values(i) * N * (1 – N / Ka) – N / (1 + N) == 0;
solutions = double(solve(eqn, N));
bifurcation_results(i, 1:length(solutions)) = solutions’;
end
% Plot bifurcation diagram
figure;
plot(ar_b_values, bifurcation_results, ‘b*’);
title(‘Bifurcation Diagram’);
xlabel(‘ar/b’);
ylabel(‘Equilibrium Points’);
% Set up the ODE function for phase plane analysis
f = @(N) ar_b * 0.4 * N .* (1 – N / Ka) – N ./ (1 + N);
% Create a grid of N values and compute their time derivatives
N_values = linspace(0, 50, 400);
dN_dtau = f(N_values);
% Plot phase plane
figure;
plot(N_values, dN_dtau);
title(‘Phase Plane Analysis’);
xlabel(‘Population Size N’);
ylabel(‘dN/dτ’);
grid on;
hold on;
% Mark zero crossings (equilibrium points)
zero_crossings = N_values(abs(dN_dtau) < 1e-3);
for i = 1:length(zero_crossings)
plot(zero_crossings(i), 0, ‘ro’);
end
hold off;Below I tried to solve Population Growth problem, I provide you the mathematical solution. Also, I create MATLAB code, however i feel like that i repeat this code to each part of this code as you can see. How could I improve this code?
Assume a continuous growth model where the function that gives the rate of change is defined as . Provide the function , which represents the population size.
If the growth of a population follows the logistic law but there is also a term for population reduction (e.g., from a predator while the members of the population are the prey), the equation that expresses the population size is of the form
where the term is given here to be and it represents a term for population reduction. The constants are positive. Normalize the equation by setting and .Find the steady solutions of the problem (real and positive) and then implement a program in MATLAB to numerically solve the dimensionless form of the equation. Make the graphical representation of the numerical solution for , with initial conditions , and respectively. What do you observe?
So we have
We are going to find the function :
To find , we integrate :
where is the integration constant, which can be determined if an initial condition is given, such as .
Now we are going to normalize the equation:
Let and . Then:
We substitute into the original equation:
Then we are going to calculate the Stationary Points:
Set :
]
For :
% Define the normalized logistic equation with reduction term
% K/a = 35, ar/b = 0.4
Ka = 35;
ar_b = 0.4;
% Define the function for the normalized logistic equation
f = @(tau, N) ar_b * N * (1 – N/Ka) – N / (1 + N);
% Time span for the simulation
tspan = [0 50]; % Adjust if needed to observe long-term behavior
% Initial conditions
N0 = [40, 25, 2, 0.05];
% Prepare the figure for plotting
figure(1);
hold on;
% Colors for different trajectories
colors = [‘r’, ‘g’, ‘b’, ‘k’]; % Red, Green, Blue, Black
% Solve the equation for each initial condition and plot
for i = 1:length(N0)
[T, N] = ode45(f, tspan, N0(i));
plot(T, N, ‘Color’, colors(i), ‘LineWidth’, 2);
legendInfo{i} = [‘N_0 = ‘ num2str(N0(i))]; % Create legend entry
end
% Add graph details
title(‘Numerical solutions of the normalized logistic equation’);
xlabel(‘Normalized time τ’);
ylabel(‘Normalized population size N’);
legend(legendInfo, ‘Location’, ‘northeastoutside’);
grid on;
hold off;
% Equilibrium analysis
syms N
eqn = ar_b * N * (1 – N / Ka) – N / (1 + N) == 0;
equilibria = double(solve(eqn, N));
% Stability analysis
f = @(N) ar_b * N * (1 – N / Ka) – N / (1 + N);
J = diff(f(N), N);
eigenvalues = double(subs(J, N, equilibria));
disp(‘Equilibrium Points and their Stability:’);
for i = 1:length(equilibria)
if real(eigenvalues(i)) < 0
stability = ‘Stable’;
else
stability = ‘Unstable’;
end
fprintf(‘N = %f: Eigenvalue = %f, %sn’, equilibria(i), eigenvalues(i), stability);
end
% Bifurcation analysis setup
ar_b_values = linspace(0.1, 1, 100);
bifurcation_results = zeros(length(ar_b_values), 10); % Adjust the columns based on expected number of roots
% Compute equilibrium points for varying ar/b
for i = 1:length(ar_b_values)
eqn = ar_b_values(i) * N * (1 – N / Ka) – N / (1 + N) == 0;
solutions = double(solve(eqn, N));
bifurcation_results(i, 1:length(solutions)) = solutions’;
end
% Plot bifurcation diagram
figure;
plot(ar_b_values, bifurcation_results, ‘b*’);
title(‘Bifurcation Diagram’);
xlabel(‘ar/b’);
ylabel(‘Equilibrium Points’);
% Set up the ODE function for phase plane analysis
f = @(N) ar_b * 0.4 * N .* (1 – N / Ka) – N ./ (1 + N);
% Create a grid of N values and compute their time derivatives
N_values = linspace(0, 50, 400);
dN_dtau = f(N_values);
% Plot phase plane
figure;
plot(N_values, dN_dtau);
title(‘Phase Plane Analysis’);
xlabel(‘Population Size N’);
ylabel(‘dN/dτ’);
grid on;
hold on;
% Mark zero crossings (equilibrium points)
zero_crossings = N_values(abs(dN_dtau) < 1e-3);
for i = 1:length(zero_crossings)
plot(zero_crossings(i), 0, ‘ro’);
end
hold off; Below I tried to solve Population Growth problem, I provide you the mathematical solution. Also, I create MATLAB code, however i feel like that i repeat this code to each part of this code as you can see. How could I improve this code?
Assume a continuous growth model where the function that gives the rate of change is defined as . Provide the function , which represents the population size.
If the growth of a population follows the logistic law but there is also a term for population reduction (e.g., from a predator while the members of the population are the prey), the equation that expresses the population size is of the form
where the term is given here to be and it represents a term for population reduction. The constants are positive. Normalize the equation by setting and .Find the steady solutions of the problem (real and positive) and then implement a program in MATLAB to numerically solve the dimensionless form of the equation. Make the graphical representation of the numerical solution for , with initial conditions , and respectively. What do you observe?
So we have
We are going to find the function :
To find , we integrate :
where is the integration constant, which can be determined if an initial condition is given, such as .
Now we are going to normalize the equation:
Let and . Then:
We substitute into the original equation:
Then we are going to calculate the Stationary Points:
Set :
]
For :
% Define the normalized logistic equation with reduction term
% K/a = 35, ar/b = 0.4
Ka = 35;
ar_b = 0.4;
% Define the function for the normalized logistic equation
f = @(tau, N) ar_b * N * (1 – N/Ka) – N / (1 + N);
% Time span for the simulation
tspan = [0 50]; % Adjust if needed to observe long-term behavior
% Initial conditions
N0 = [40, 25, 2, 0.05];
% Prepare the figure for plotting
figure(1);
hold on;
% Colors for different trajectories
colors = [‘r’, ‘g’, ‘b’, ‘k’]; % Red, Green, Blue, Black
% Solve the equation for each initial condition and plot
for i = 1:length(N0)
[T, N] = ode45(f, tspan, N0(i));
plot(T, N, ‘Color’, colors(i), ‘LineWidth’, 2);
legendInfo{i} = [‘N_0 = ‘ num2str(N0(i))]; % Create legend entry
end
% Add graph details
title(‘Numerical solutions of the normalized logistic equation’);
xlabel(‘Normalized time τ’);
ylabel(‘Normalized population size N’);
legend(legendInfo, ‘Location’, ‘northeastoutside’);
grid on;
hold off;
% Equilibrium analysis
syms N
eqn = ar_b * N * (1 – N / Ka) – N / (1 + N) == 0;
equilibria = double(solve(eqn, N));
% Stability analysis
f = @(N) ar_b * N * (1 – N / Ka) – N / (1 + N);
J = diff(f(N), N);
eigenvalues = double(subs(J, N, equilibria));
disp(‘Equilibrium Points and their Stability:’);
for i = 1:length(equilibria)
if real(eigenvalues(i)) < 0
stability = ‘Stable’;
else
stability = ‘Unstable’;
end
fprintf(‘N = %f: Eigenvalue = %f, %sn’, equilibria(i), eigenvalues(i), stability);
end
% Bifurcation analysis setup
ar_b_values = linspace(0.1, 1, 100);
bifurcation_results = zeros(length(ar_b_values), 10); % Adjust the columns based on expected number of roots
% Compute equilibrium points for varying ar/b
for i = 1:length(ar_b_values)
eqn = ar_b_values(i) * N * (1 – N / Ka) – N / (1 + N) == 0;
solutions = double(solve(eqn, N));
bifurcation_results(i, 1:length(solutions)) = solutions’;
end
% Plot bifurcation diagram
figure;
plot(ar_b_values, bifurcation_results, ‘b*’);
title(‘Bifurcation Diagram’);
xlabel(‘ar/b’);
ylabel(‘Equilibrium Points’);
% Set up the ODE function for phase plane analysis
f = @(N) ar_b * 0.4 * N .* (1 – N / Ka) – N ./ (1 + N);
% Create a grid of N values and compute their time derivatives
N_values = linspace(0, 50, 400);
dN_dtau = f(N_values);
% Plot phase plane
figure;
plot(N_values, dN_dtau);
title(‘Phase Plane Analysis’);
xlabel(‘Population Size N’);
ylabel(‘dN/dτ’);
grid on;
hold on;
% Mark zero crossings (equilibrium points)
zero_crossings = N_values(abs(dN_dtau) < 1e-3);
for i = 1:length(zero_crossings)
plot(zero_crossings(i), 0, ‘ro’);
end
hold off; differential equations, equation, plotting, plot, ode, homework MATLAB Answers — New Questions
How to solve SIR model with using DTM (Differential Transform Method)
I am trying to use dtm for solving SIR model, Although my code is run but I think the DTM part is wrong. I need help for DTM part
here is my code
function sir_model_dtm()
% Parameters
alpha = 0.3; % Infection rate
beta = 0.1; % Recovery rate
N = 1000; % Total population
I0 = 1; % Initial number of infected individuals
R0 = 0; % Initial number of recovered individuals
S0 = N – I0 – R0; % Initial number of susceptible individuals
% Time parameters
T = 100; % Total simulation time
dt = 1; % Time step
% Initialize arrays to store results
S = zeros(1, T);
I = zeros(1, T);
R = zeros(1, T);
% Initial conditions
S(1) = S0;
I(1) = I0;
R(1) = R0;
% Simulate the SIR model using DTM
for t = 2:T
% Compute new values
S(t) = S(t-1) – alpha*S(t-1)*I(t-1)/N * dt;
I(t) = I(t-1) + (alpha*S(t-1)*I(t-1)/N – beta*I(t-1)) * dt;
R(t) = R(t-1) + beta*I(t-1) * dt;
end
% Plot the results
t = 0:dt:T-dt;
plot(t, S, ‘b’, t, I, ‘r’, t, R, ‘g’, ‘LineWidth’, 2);
legend(‘Susceptible’, ‘Infectious’, ‘Recovered’);
xlabel(‘Time’);
ylabel(‘Number of individuals’);
title(‘SIR Model’);
endI am trying to use dtm for solving SIR model, Although my code is run but I think the DTM part is wrong. I need help for DTM part
here is my code
function sir_model_dtm()
% Parameters
alpha = 0.3; % Infection rate
beta = 0.1; % Recovery rate
N = 1000; % Total population
I0 = 1; % Initial number of infected individuals
R0 = 0; % Initial number of recovered individuals
S0 = N – I0 – R0; % Initial number of susceptible individuals
% Time parameters
T = 100; % Total simulation time
dt = 1; % Time step
% Initialize arrays to store results
S = zeros(1, T);
I = zeros(1, T);
R = zeros(1, T);
% Initial conditions
S(1) = S0;
I(1) = I0;
R(1) = R0;
% Simulate the SIR model using DTM
for t = 2:T
% Compute new values
S(t) = S(t-1) – alpha*S(t-1)*I(t-1)/N * dt;
I(t) = I(t-1) + (alpha*S(t-1)*I(t-1)/N – beta*I(t-1)) * dt;
R(t) = R(t-1) + beta*I(t-1) * dt;
end
% Plot the results
t = 0:dt:T-dt;
plot(t, S, ‘b’, t, I, ‘r’, t, R, ‘g’, ‘LineWidth’, 2);
legend(‘Susceptible’, ‘Infectious’, ‘Recovered’);
xlabel(‘Time’);
ylabel(‘Number of individuals’);
title(‘SIR Model’);
end I am trying to use dtm for solving SIR model, Although my code is run but I think the DTM part is wrong. I need help for DTM part
here is my code
function sir_model_dtm()
% Parameters
alpha = 0.3; % Infection rate
beta = 0.1; % Recovery rate
N = 1000; % Total population
I0 = 1; % Initial number of infected individuals
R0 = 0; % Initial number of recovered individuals
S0 = N – I0 – R0; % Initial number of susceptible individuals
% Time parameters
T = 100; % Total simulation time
dt = 1; % Time step
% Initialize arrays to store results
S = zeros(1, T);
I = zeros(1, T);
R = zeros(1, T);
% Initial conditions
S(1) = S0;
I(1) = I0;
R(1) = R0;
% Simulate the SIR model using DTM
for t = 2:T
% Compute new values
S(t) = S(t-1) – alpha*S(t-1)*I(t-1)/N * dt;
I(t) = I(t-1) + (alpha*S(t-1)*I(t-1)/N – beta*I(t-1)) * dt;
R(t) = R(t-1) + beta*I(t-1) * dt;
end
% Plot the results
t = 0:dt:T-dt;
plot(t, S, ‘b’, t, I, ‘r’, t, R, ‘g’, ‘LineWidth’, 2);
legend(‘Susceptible’, ‘Infectious’, ‘Recovered’);
xlabel(‘Time’);
ylabel(‘Number of individuals’);
title(‘SIR Model’);
end sir, matlab, dtm, differential equations, transform method, nonlinear, covid19 MATLAB Answers — New Questions
Why does my ode45 return a solution with the first values as zero despite I supplying non-zero initial conditions?
In the following code to simulate Pond volume and water temperature changes the code returns the solution (Y) with the first values of pondvolume and water temperature as 0,0. What could be the problem and ho can I solve it?
% Solar constant [MJ m-2 min-1]
Gsc = 0.08;
lat = 0; % Latitude
% Define simulation period
startdate = datetime(2023, 01, 01, ‘Format’, ‘uuuu-MM-dd’);
finishdate = datetime(2023, 06, 30, ‘Format’, ‘uuuu-MM-dd’);
tspans = (1:1:days(finishdate – startdate) + 1);
% Initialize arrays to store MM, doy, and dd values
MM_array_s = zeros(1, days(finishdate – startdate) + 1);
doy_array_s = zeros(1, days(finishdate – startdate) + 1);
dd_array_s = zeros(1, days(finishdate – startdate) + 1);
% Convert date to datetime object
for idx = 1:days(finishdate – startdate) + 1
current_date = startdate + days(idx – 1);
MM = month(current_date);
dd = day(current_date);
doy = days(current_date – datetime(year(current_date), 1, 1)) + 1;
% Store values in arrays
MM_array_s(idx) = MM;
doy_array_s(idx) = doy;
dd_array_s(idx) = dd;
end
CWR = 20; % To be read from Aquacrop
A_Irr = 200;
Irr_data = A_Irr * CWR / 1000*ones(length(tspans),1);
T_a_data = 25 *ones(length(tspans),1); % Later read from file/ it should be a data series
U2_data = 1.3*ones(length(tspans),1); % Read from file
RH_data = 0.75*ones(length(tspans),1); % Read from file
Y= zeros(length(tspans), 2);
Rho_net_values =zeros(length(tspans), 1);
for t=1:length(tspans)-1
T_a =T_a_data(t);
U2 = U2_data(t);
RH = RH_data(t);
Irr = Irr_data(t);
doy_array = doy_array_s(t);
% Convert latitude to radians
phi = deg2rad(lat);
% Calculate inverse relative distance Earth-Sun (dr)
dr = 1 + 0.033 * cos(2 .* pi .* doy_array ./ 365);
% Calculate solar declination (delta)
delta = 0.409 * sin(((2 * pi ./ 365)* doy_array) – 1.39);
% Calculate sunset hour angle (ws)
ws = acos(-tan(phi) * tan(delta));
% Calculate extraterrestrial radiation (Ra)
Ra = 1000*extraterrestrialRadiation(Gsc, dr, pi, phi, ws, delta);
% Display the result
% Constants and parameters
As = 0.06;
as = 0.25;
bs = 0.5;
%N = (2 / 15) .* acos(-tand(lat) .* tand(rad2deg(delta)));
N = (24/pi)*ws;
n = 11; %to be provided as a data series
Rs = (as + (bs .* (n ./ N))) .* Ra;
% Calculate net shortwave solar radiation (and photoperiod/24(phi_Light))
pi_light = N / 24;
Rho_SWR = Rs * (1 – As);
% Calculate rho_an (the difference between the incident and reflected components of long-wave radiation)
sigma = 4.896 * 10^(-6);
r = 0.36; % Change the value as necessary
C_c = 0.5; % Read from file/enter
epslon_a = 0.937 * 10^-5 * (273+T_a).^2 * (1 + 0.17 * C_c^2);
Rho_an = (1 – r) * epslon_a * sigma .* (273+T_a).^4;
% Calculate Water Surface Radiation (HO2_heat_Emm)
Initial_T_w = 27;
T_w = Initial_T_w; % To be simulated first
epslon_w = 0.97;
Rho_HO2_heat_Emm = epslon_w * sigma * (273+T_w).^4;
% Calculate Evaporative Heat Loss (Evap_HLoss)
bo = 368.61;
lambda = 311.02;
es = 25.37 * exp(17.62 – 5271 ./ (273+T_w));
ea = RH .* 25.37 .* exp(17.62 – 5271 ./ (273+T_a));
z = 1000; % Entered in the app
P = 760 / (10^(z / 19748.2));
T_wv = ((273+T_w) / (1.0 – (0.378 * es / P)));
T_av = ((273+T_a) / (1.0 – (0.378 * ea / P)));
Rho_Evap_HLoss = (es – ea) * (lambda * ((T_wv – T_av))^(1 / 3) + bo * U2);
% Calculate Conductive Heat Loss or Gain (Heat_cond)
Rho_Heat_cond = Rho_Evap_HLoss * 0.61 * 10^-3 * P * (((273+T_w) – (273+T_a)) / (es – ea));
Rho_net= Rho_SWR + Rho_an – Rho_HO2_heat_Emm – Rho_Evap_HLoss + Rho_Heat_cond;
% Define Rho_net as an anonymous function of time
%Computation of water balance components
A = 100;
pond_depth = 1;
V = A * pond_depth;
dmin = 0.8;
dcurr = 0.6;
dmax = pond_depth;
Ir = 12.923;
if Ir == 0
Qi = A * (dmin – dcurr) / tspans(2);
else
Qi = Ir / 100 * V;
end
Er = 10;
if Er == 0
Qe = A * (dcurr – dmax) / tspans(2);
else
Qe = Er / 100 * V;
end
pd = 10; % To be read from a file
PCP = A * pd / 1000;
Density_w = 1000;
Latent_vapw = 2260;
Evap = A * Rho_Evap_HLoss / (Density_w * Latent_vapw);
Sr = 5;
Seep = A * Sr / 1000;
% Initial conditions for the ODEs
T_win = 27; % Initial water temperature
T_wout = 27;
Cpw = 4.18;
% Define your ODEs
dVdt = @(t, Y) Qi + PCP – Qe + Evap + Seep – Irr;
dTdt = @(t, Y) Qi * T_win / Y(1) – Qe * T_wout / Y(1) + Rho_net / (Density_w * Cpw * pond_depth) – Y(2) / Y(1) * dVdt(t,Y);
% Combine the ODEs into a single function
dYdt = @(t, Y) [dVdt(t, Y); dTdt(t, Y)];
% Set initial conditions
Initial_conditions10 = [V; Initial_T_w]; % Ensure that this is a column vector
% Solve the system of ODEs using ode45
options = odeset(‘AbsTol’, 1e-6, ‘RelTol’, 1e-6);
[t_integrated10,Y_integrated]=ode45(@(t,Y) dYdt(t,Y),tspans(t:t+1),Initial_conditions10);
Y(t+1,:) = Y_integrated(end,:);
Initial_conditions10=Y(t+1,:);
Rho_net_values(t+1) = Rho_net;
end
disp([‘Extraterrestrial Radiation (Ra): ‘ num2str(Ra(1)) ‘ kJ/m^2/day’]); % Displaying only the first value
figure
plot(tspans(1):tspans(end), Rho_net_values(tspans(1):tspans(end)), ‘.’, ‘markersize’, 3), grid on,
title(‘rho_{net}’)
% Extract results
V_solution = Y(:, 1);
T_w_solution = Y(:, 2);
% Display or use the solutions as needed
disp(‘Volume (V) solution:’);
disp(V_solution);
disp(‘Water Temperature (T_w) solution:’);
disp(T_w_solution);
% Plot the results
figure;
subplot(2, 1, 1);
plot(tspans, V_solution); grid on
title(‘Volume (V) vs Time’);
xlabel(‘Time’);
ylabel(‘Volume (V)’);
subplot(2, 1, 2);
plot(tspans, T_w_solution); grid on
title(‘Water Temperature (T_w) vs Time’);
xlabel(‘Time’);
ylabel(‘Water Temperature (T_w)’);
function Ra = extraterrestrialRadiation(Gsc, dr, pi, phi, ws, delta)
% Calculate extraterrestrial radiation (Ra)
Ra = (24 * 60 / pi) * Gsc * dr .* (ws .* sin(phi) .* sin(delta) + cos(phi) .* cos(delta) .* sin(ws));
endIn the following code to simulate Pond volume and water temperature changes the code returns the solution (Y) with the first values of pondvolume and water temperature as 0,0. What could be the problem and ho can I solve it?
% Solar constant [MJ m-2 min-1]
Gsc = 0.08;
lat = 0; % Latitude
% Define simulation period
startdate = datetime(2023, 01, 01, ‘Format’, ‘uuuu-MM-dd’);
finishdate = datetime(2023, 06, 30, ‘Format’, ‘uuuu-MM-dd’);
tspans = (1:1:days(finishdate – startdate) + 1);
% Initialize arrays to store MM, doy, and dd values
MM_array_s = zeros(1, days(finishdate – startdate) + 1);
doy_array_s = zeros(1, days(finishdate – startdate) + 1);
dd_array_s = zeros(1, days(finishdate – startdate) + 1);
% Convert date to datetime object
for idx = 1:days(finishdate – startdate) + 1
current_date = startdate + days(idx – 1);
MM = month(current_date);
dd = day(current_date);
doy = days(current_date – datetime(year(current_date), 1, 1)) + 1;
% Store values in arrays
MM_array_s(idx) = MM;
doy_array_s(idx) = doy;
dd_array_s(idx) = dd;
end
CWR = 20; % To be read from Aquacrop
A_Irr = 200;
Irr_data = A_Irr * CWR / 1000*ones(length(tspans),1);
T_a_data = 25 *ones(length(tspans),1); % Later read from file/ it should be a data series
U2_data = 1.3*ones(length(tspans),1); % Read from file
RH_data = 0.75*ones(length(tspans),1); % Read from file
Y= zeros(length(tspans), 2);
Rho_net_values =zeros(length(tspans), 1);
for t=1:length(tspans)-1
T_a =T_a_data(t);
U2 = U2_data(t);
RH = RH_data(t);
Irr = Irr_data(t);
doy_array = doy_array_s(t);
% Convert latitude to radians
phi = deg2rad(lat);
% Calculate inverse relative distance Earth-Sun (dr)
dr = 1 + 0.033 * cos(2 .* pi .* doy_array ./ 365);
% Calculate solar declination (delta)
delta = 0.409 * sin(((2 * pi ./ 365)* doy_array) – 1.39);
% Calculate sunset hour angle (ws)
ws = acos(-tan(phi) * tan(delta));
% Calculate extraterrestrial radiation (Ra)
Ra = 1000*extraterrestrialRadiation(Gsc, dr, pi, phi, ws, delta);
% Display the result
% Constants and parameters
As = 0.06;
as = 0.25;
bs = 0.5;
%N = (2 / 15) .* acos(-tand(lat) .* tand(rad2deg(delta)));
N = (24/pi)*ws;
n = 11; %to be provided as a data series
Rs = (as + (bs .* (n ./ N))) .* Ra;
% Calculate net shortwave solar radiation (and photoperiod/24(phi_Light))
pi_light = N / 24;
Rho_SWR = Rs * (1 – As);
% Calculate rho_an (the difference between the incident and reflected components of long-wave radiation)
sigma = 4.896 * 10^(-6);
r = 0.36; % Change the value as necessary
C_c = 0.5; % Read from file/enter
epslon_a = 0.937 * 10^-5 * (273+T_a).^2 * (1 + 0.17 * C_c^2);
Rho_an = (1 – r) * epslon_a * sigma .* (273+T_a).^4;
% Calculate Water Surface Radiation (HO2_heat_Emm)
Initial_T_w = 27;
T_w = Initial_T_w; % To be simulated first
epslon_w = 0.97;
Rho_HO2_heat_Emm = epslon_w * sigma * (273+T_w).^4;
% Calculate Evaporative Heat Loss (Evap_HLoss)
bo = 368.61;
lambda = 311.02;
es = 25.37 * exp(17.62 – 5271 ./ (273+T_w));
ea = RH .* 25.37 .* exp(17.62 – 5271 ./ (273+T_a));
z = 1000; % Entered in the app
P = 760 / (10^(z / 19748.2));
T_wv = ((273+T_w) / (1.0 – (0.378 * es / P)));
T_av = ((273+T_a) / (1.0 – (0.378 * ea / P)));
Rho_Evap_HLoss = (es – ea) * (lambda * ((T_wv – T_av))^(1 / 3) + bo * U2);
% Calculate Conductive Heat Loss or Gain (Heat_cond)
Rho_Heat_cond = Rho_Evap_HLoss * 0.61 * 10^-3 * P * (((273+T_w) – (273+T_a)) / (es – ea));
Rho_net= Rho_SWR + Rho_an – Rho_HO2_heat_Emm – Rho_Evap_HLoss + Rho_Heat_cond;
% Define Rho_net as an anonymous function of time
%Computation of water balance components
A = 100;
pond_depth = 1;
V = A * pond_depth;
dmin = 0.8;
dcurr = 0.6;
dmax = pond_depth;
Ir = 12.923;
if Ir == 0
Qi = A * (dmin – dcurr) / tspans(2);
else
Qi = Ir / 100 * V;
end
Er = 10;
if Er == 0
Qe = A * (dcurr – dmax) / tspans(2);
else
Qe = Er / 100 * V;
end
pd = 10; % To be read from a file
PCP = A * pd / 1000;
Density_w = 1000;
Latent_vapw = 2260;
Evap = A * Rho_Evap_HLoss / (Density_w * Latent_vapw);
Sr = 5;
Seep = A * Sr / 1000;
% Initial conditions for the ODEs
T_win = 27; % Initial water temperature
T_wout = 27;
Cpw = 4.18;
% Define your ODEs
dVdt = @(t, Y) Qi + PCP – Qe + Evap + Seep – Irr;
dTdt = @(t, Y) Qi * T_win / Y(1) – Qe * T_wout / Y(1) + Rho_net / (Density_w * Cpw * pond_depth) – Y(2) / Y(1) * dVdt(t,Y);
% Combine the ODEs into a single function
dYdt = @(t, Y) [dVdt(t, Y); dTdt(t, Y)];
% Set initial conditions
Initial_conditions10 = [V; Initial_T_w]; % Ensure that this is a column vector
% Solve the system of ODEs using ode45
options = odeset(‘AbsTol’, 1e-6, ‘RelTol’, 1e-6);
[t_integrated10,Y_integrated]=ode45(@(t,Y) dYdt(t,Y),tspans(t:t+1),Initial_conditions10);
Y(t+1,:) = Y_integrated(end,:);
Initial_conditions10=Y(t+1,:);
Rho_net_values(t+1) = Rho_net;
end
disp([‘Extraterrestrial Radiation (Ra): ‘ num2str(Ra(1)) ‘ kJ/m^2/day’]); % Displaying only the first value
figure
plot(tspans(1):tspans(end), Rho_net_values(tspans(1):tspans(end)), ‘.’, ‘markersize’, 3), grid on,
title(‘rho_{net}’)
% Extract results
V_solution = Y(:, 1);
T_w_solution = Y(:, 2);
% Display or use the solutions as needed
disp(‘Volume (V) solution:’);
disp(V_solution);
disp(‘Water Temperature (T_w) solution:’);
disp(T_w_solution);
% Plot the results
figure;
subplot(2, 1, 1);
plot(tspans, V_solution); grid on
title(‘Volume (V) vs Time’);
xlabel(‘Time’);
ylabel(‘Volume (V)’);
subplot(2, 1, 2);
plot(tspans, T_w_solution); grid on
title(‘Water Temperature (T_w) vs Time’);
xlabel(‘Time’);
ylabel(‘Water Temperature (T_w)’);
function Ra = extraterrestrialRadiation(Gsc, dr, pi, phi, ws, delta)
% Calculate extraterrestrial radiation (Ra)
Ra = (24 * 60 / pi) * Gsc * dr .* (ws .* sin(phi) .* sin(delta) + cos(phi) .* cos(delta) .* sin(ws));
end In the following code to simulate Pond volume and water temperature changes the code returns the solution (Y) with the first values of pondvolume and water temperature as 0,0. What could be the problem and ho can I solve it?
% Solar constant [MJ m-2 min-1]
Gsc = 0.08;
lat = 0; % Latitude
% Define simulation period
startdate = datetime(2023, 01, 01, ‘Format’, ‘uuuu-MM-dd’);
finishdate = datetime(2023, 06, 30, ‘Format’, ‘uuuu-MM-dd’);
tspans = (1:1:days(finishdate – startdate) + 1);
% Initialize arrays to store MM, doy, and dd values
MM_array_s = zeros(1, days(finishdate – startdate) + 1);
doy_array_s = zeros(1, days(finishdate – startdate) + 1);
dd_array_s = zeros(1, days(finishdate – startdate) + 1);
% Convert date to datetime object
for idx = 1:days(finishdate – startdate) + 1
current_date = startdate + days(idx – 1);
MM = month(current_date);
dd = day(current_date);
doy = days(current_date – datetime(year(current_date), 1, 1)) + 1;
% Store values in arrays
MM_array_s(idx) = MM;
doy_array_s(idx) = doy;
dd_array_s(idx) = dd;
end
CWR = 20; % To be read from Aquacrop
A_Irr = 200;
Irr_data = A_Irr * CWR / 1000*ones(length(tspans),1);
T_a_data = 25 *ones(length(tspans),1); % Later read from file/ it should be a data series
U2_data = 1.3*ones(length(tspans),1); % Read from file
RH_data = 0.75*ones(length(tspans),1); % Read from file
Y= zeros(length(tspans), 2);
Rho_net_values =zeros(length(tspans), 1);
for t=1:length(tspans)-1
T_a =T_a_data(t);
U2 = U2_data(t);
RH = RH_data(t);
Irr = Irr_data(t);
doy_array = doy_array_s(t);
% Convert latitude to radians
phi = deg2rad(lat);
% Calculate inverse relative distance Earth-Sun (dr)
dr = 1 + 0.033 * cos(2 .* pi .* doy_array ./ 365);
% Calculate solar declination (delta)
delta = 0.409 * sin(((2 * pi ./ 365)* doy_array) – 1.39);
% Calculate sunset hour angle (ws)
ws = acos(-tan(phi) * tan(delta));
% Calculate extraterrestrial radiation (Ra)
Ra = 1000*extraterrestrialRadiation(Gsc, dr, pi, phi, ws, delta);
% Display the result
% Constants and parameters
As = 0.06;
as = 0.25;
bs = 0.5;
%N = (2 / 15) .* acos(-tand(lat) .* tand(rad2deg(delta)));
N = (24/pi)*ws;
n = 11; %to be provided as a data series
Rs = (as + (bs .* (n ./ N))) .* Ra;
% Calculate net shortwave solar radiation (and photoperiod/24(phi_Light))
pi_light = N / 24;
Rho_SWR = Rs * (1 – As);
% Calculate rho_an (the difference between the incident and reflected components of long-wave radiation)
sigma = 4.896 * 10^(-6);
r = 0.36; % Change the value as necessary
C_c = 0.5; % Read from file/enter
epslon_a = 0.937 * 10^-5 * (273+T_a).^2 * (1 + 0.17 * C_c^2);
Rho_an = (1 – r) * epslon_a * sigma .* (273+T_a).^4;
% Calculate Water Surface Radiation (HO2_heat_Emm)
Initial_T_w = 27;
T_w = Initial_T_w; % To be simulated first
epslon_w = 0.97;
Rho_HO2_heat_Emm = epslon_w * sigma * (273+T_w).^4;
% Calculate Evaporative Heat Loss (Evap_HLoss)
bo = 368.61;
lambda = 311.02;
es = 25.37 * exp(17.62 – 5271 ./ (273+T_w));
ea = RH .* 25.37 .* exp(17.62 – 5271 ./ (273+T_a));
z = 1000; % Entered in the app
P = 760 / (10^(z / 19748.2));
T_wv = ((273+T_w) / (1.0 – (0.378 * es / P)));
T_av = ((273+T_a) / (1.0 – (0.378 * ea / P)));
Rho_Evap_HLoss = (es – ea) * (lambda * ((T_wv – T_av))^(1 / 3) + bo * U2);
% Calculate Conductive Heat Loss or Gain (Heat_cond)
Rho_Heat_cond = Rho_Evap_HLoss * 0.61 * 10^-3 * P * (((273+T_w) – (273+T_a)) / (es – ea));
Rho_net= Rho_SWR + Rho_an – Rho_HO2_heat_Emm – Rho_Evap_HLoss + Rho_Heat_cond;
% Define Rho_net as an anonymous function of time
%Computation of water balance components
A = 100;
pond_depth = 1;
V = A * pond_depth;
dmin = 0.8;
dcurr = 0.6;
dmax = pond_depth;
Ir = 12.923;
if Ir == 0
Qi = A * (dmin – dcurr) / tspans(2);
else
Qi = Ir / 100 * V;
end
Er = 10;
if Er == 0
Qe = A * (dcurr – dmax) / tspans(2);
else
Qe = Er / 100 * V;
end
pd = 10; % To be read from a file
PCP = A * pd / 1000;
Density_w = 1000;
Latent_vapw = 2260;
Evap = A * Rho_Evap_HLoss / (Density_w * Latent_vapw);
Sr = 5;
Seep = A * Sr / 1000;
% Initial conditions for the ODEs
T_win = 27; % Initial water temperature
T_wout = 27;
Cpw = 4.18;
% Define your ODEs
dVdt = @(t, Y) Qi + PCP – Qe + Evap + Seep – Irr;
dTdt = @(t, Y) Qi * T_win / Y(1) – Qe * T_wout / Y(1) + Rho_net / (Density_w * Cpw * pond_depth) – Y(2) / Y(1) * dVdt(t,Y);
% Combine the ODEs into a single function
dYdt = @(t, Y) [dVdt(t, Y); dTdt(t, Y)];
% Set initial conditions
Initial_conditions10 = [V; Initial_T_w]; % Ensure that this is a column vector
% Solve the system of ODEs using ode45
options = odeset(‘AbsTol’, 1e-6, ‘RelTol’, 1e-6);
[t_integrated10,Y_integrated]=ode45(@(t,Y) dYdt(t,Y),tspans(t:t+1),Initial_conditions10);
Y(t+1,:) = Y_integrated(end,:);
Initial_conditions10=Y(t+1,:);
Rho_net_values(t+1) = Rho_net;
end
disp([‘Extraterrestrial Radiation (Ra): ‘ num2str(Ra(1)) ‘ kJ/m^2/day’]); % Displaying only the first value
figure
plot(tspans(1):tspans(end), Rho_net_values(tspans(1):tspans(end)), ‘.’, ‘markersize’, 3), grid on,
title(‘rho_{net}’)
% Extract results
V_solution = Y(:, 1);
T_w_solution = Y(:, 2);
% Display or use the solutions as needed
disp(‘Volume (V) solution:’);
disp(V_solution);
disp(‘Water Temperature (T_w) solution:’);
disp(T_w_solution);
% Plot the results
figure;
subplot(2, 1, 1);
plot(tspans, V_solution); grid on
title(‘Volume (V) vs Time’);
xlabel(‘Time’);
ylabel(‘Volume (V)’);
subplot(2, 1, 2);
plot(tspans, T_w_solution); grid on
title(‘Water Temperature (T_w) vs Time’);
xlabel(‘Time’);
ylabel(‘Water Temperature (T_w)’);
function Ra = extraterrestrialRadiation(Gsc, dr, pi, phi, ws, delta)
% Calculate extraterrestrial radiation (Ra)
Ra = (24 * 60 / pi) * Gsc * dr .* (ws .* sin(phi) .* sin(delta) + cos(phi) .* cos(delta) .* sin(ws));
end ode45 MATLAB Answers — New Questions
3D U-Net Semantic Segmentation on custom CT dataset
Hello:
I am trying to apply the concept and sample code of the tutorial "3D brain tumor segmentation using deep learning" found on the below link –
https://in.mathworks.com/help/deeplearning/examples/segment-3d-brain-tumor-using-deep-learning.html
to a custom CT dataset in order to segment the lymph nodes. In my use case also there are 2 classes i.e background and lymph nodes. The current dataset has less data points (70 in total) and the split after preprocessing is 56 for train, 10 for validation and 4 for test.
I have modified the preprocessing code to accept the custom dataset and am cropping the ROI (i.e. the cubiod region around the abdomen which has the ground truth for the lumph nodes from the full CT Torso Volume)
I have visualized the patches that are extracted by the randomPatchExtractorDatastore and found that there is a class imbalance i.e. 4 out of 5 times the extracted patch has a Lymph node portion and 1 out of 5 times – it has the background portion. So, this may be causing an issue is what I am suspecting. (The dice accuracy suggest the same – as mentioed at the later part of this text)
In my case the volume image are 1 channel where as in the tutorial the volume image are 4 channel, so I have changed the input_layer to [64 64 64 1]
The code is working and there are no errors. The training process is also working but the accuracy starts at 100% and the loss starts at approx 1. So, this is unlike the graph shown in the tutorial where the accuracy gradually increase and reaches about 72 %. To train 1 EPOCH it takes like 75 mins on RTX 2080Ti so I tried training for 10 epochs as I was suspicious about the class imbalance of the randomly extracted patches.
I used PatchPerImage = 32 and the initial learning rate at 0.001 for the 1st 5 EPOCHs. The validation freq is 10.
Training Graph is as below –
The segmentation test shows that the model is just identifing the background and not learning to segment the lymph node. The Quantify Segmentation Accuracy section of the code suggest the same thing that the lymph nodes are not identified by the newtork.
Average Dice Score of the background across 4 test volumes = 0.99685 and
Average Dice Score of the lymph nodes across 4 test volumes = 0
Box plot of the Dice Score is as below –
I need some help and guidance on the following –
So, what can be the reason for this. Is class imbalance the reason or lack of training or few datapoint ?
How can i ensure that the patches in the randomPatchExtractorDatastore are equally balance accross both the classes i.e. Background and Lymph Nodes ?
Also, should i train the network for more epochs (like 50 or 100) before evaluating its efficacy ?
Is the limited data point the problem. I only have 175 total datapoints in the comprehensive dataset. So, should i use a higher patchPerImage value like 64 (instead of 16 as used in the tutorial)
Thanks for your guidance.Hello:
I am trying to apply the concept and sample code of the tutorial "3D brain tumor segmentation using deep learning" found on the below link –
https://in.mathworks.com/help/deeplearning/examples/segment-3d-brain-tumor-using-deep-learning.html
to a custom CT dataset in order to segment the lymph nodes. In my use case also there are 2 classes i.e background and lymph nodes. The current dataset has less data points (70 in total) and the split after preprocessing is 56 for train, 10 for validation and 4 for test.
I have modified the preprocessing code to accept the custom dataset and am cropping the ROI (i.e. the cubiod region around the abdomen which has the ground truth for the lumph nodes from the full CT Torso Volume)
I have visualized the patches that are extracted by the randomPatchExtractorDatastore and found that there is a class imbalance i.e. 4 out of 5 times the extracted patch has a Lymph node portion and 1 out of 5 times – it has the background portion. So, this may be causing an issue is what I am suspecting. (The dice accuracy suggest the same – as mentioed at the later part of this text)
In my case the volume image are 1 channel where as in the tutorial the volume image are 4 channel, so I have changed the input_layer to [64 64 64 1]
The code is working and there are no errors. The training process is also working but the accuracy starts at 100% and the loss starts at approx 1. So, this is unlike the graph shown in the tutorial where the accuracy gradually increase and reaches about 72 %. To train 1 EPOCH it takes like 75 mins on RTX 2080Ti so I tried training for 10 epochs as I was suspicious about the class imbalance of the randomly extracted patches.
I used PatchPerImage = 32 and the initial learning rate at 0.001 for the 1st 5 EPOCHs. The validation freq is 10.
Training Graph is as below –
The segmentation test shows that the model is just identifing the background and not learning to segment the lymph node. The Quantify Segmentation Accuracy section of the code suggest the same thing that the lymph nodes are not identified by the newtork.
Average Dice Score of the background across 4 test volumes = 0.99685 and
Average Dice Score of the lymph nodes across 4 test volumes = 0
Box plot of the Dice Score is as below –
I need some help and guidance on the following –
So, what can be the reason for this. Is class imbalance the reason or lack of training or few datapoint ?
How can i ensure that the patches in the randomPatchExtractorDatastore are equally balance accross both the classes i.e. Background and Lymph Nodes ?
Also, should i train the network for more epochs (like 50 or 100) before evaluating its efficacy ?
Is the limited data point the problem. I only have 175 total datapoints in the comprehensive dataset. So, should i use a higher patchPerImage value like 64 (instead of 16 as used in the tutorial)
Thanks for your guidance. Hello:
I am trying to apply the concept and sample code of the tutorial "3D brain tumor segmentation using deep learning" found on the below link –
https://in.mathworks.com/help/deeplearning/examples/segment-3d-brain-tumor-using-deep-learning.html
to a custom CT dataset in order to segment the lymph nodes. In my use case also there are 2 classes i.e background and lymph nodes. The current dataset has less data points (70 in total) and the split after preprocessing is 56 for train, 10 for validation and 4 for test.
I have modified the preprocessing code to accept the custom dataset and am cropping the ROI (i.e. the cubiod region around the abdomen which has the ground truth for the lumph nodes from the full CT Torso Volume)
I have visualized the patches that are extracted by the randomPatchExtractorDatastore and found that there is a class imbalance i.e. 4 out of 5 times the extracted patch has a Lymph node portion and 1 out of 5 times – it has the background portion. So, this may be causing an issue is what I am suspecting. (The dice accuracy suggest the same – as mentioed at the later part of this text)
In my case the volume image are 1 channel where as in the tutorial the volume image are 4 channel, so I have changed the input_layer to [64 64 64 1]
The code is working and there are no errors. The training process is also working but the accuracy starts at 100% and the loss starts at approx 1. So, this is unlike the graph shown in the tutorial where the accuracy gradually increase and reaches about 72 %. To train 1 EPOCH it takes like 75 mins on RTX 2080Ti so I tried training for 10 epochs as I was suspicious about the class imbalance of the randomly extracted patches.
I used PatchPerImage = 32 and the initial learning rate at 0.001 for the 1st 5 EPOCHs. The validation freq is 10.
Training Graph is as below –
The segmentation test shows that the model is just identifing the background and not learning to segment the lymph node. The Quantify Segmentation Accuracy section of the code suggest the same thing that the lymph nodes are not identified by the newtork.
Average Dice Score of the background across 4 test volumes = 0.99685 and
Average Dice Score of the lymph nodes across 4 test volumes = 0
Box plot of the Dice Score is as below –
I need some help and guidance on the following –
So, what can be the reason for this. Is class imbalance the reason or lack of training or few datapoint ?
How can i ensure that the patches in the randomPatchExtractorDatastore are equally balance accross both the classes i.e. Background and Lymph Nodes ?
Also, should i train the network for more epochs (like 50 or 100) before evaluating its efficacy ?
Is the limited data point the problem. I only have 175 total datapoints in the comprehensive dataset. So, should i use a higher patchPerImage value like 64 (instead of 16 as used in the tutorial)
Thanks for your guidance. 3d, unet, semantic segmentation, deep learning, custom dataset, own dataset, class imbalance, randompatchextractordatastore, random patch extractor datastore MATLAB Answers — New Questions
Loaded quaternion but still cannot find slerp
After installing the Sensor Fusion toolbox, Matlab reopens. I used the following code:
q1 = quaternion([75,-20,-10],"eulerd","ZYZ","frame");
q2 = quaternion([-45,20,30],"eulerd","ZYZ","frame");
T = 0.5;
b = slerp(q1,q2,T);
But MATLAB returns error:
Unrecognized function or variable ‘slerp’.
When I look it up, the only posts say quaternion must be loaded, and it is indeed loaded since I can see Quaternion objects for q1 and q2. Then, I also installed navigation toolbox, but the problem remains.After installing the Sensor Fusion toolbox, Matlab reopens. I used the following code:
q1 = quaternion([75,-20,-10],"eulerd","ZYZ","frame");
q2 = quaternion([-45,20,30],"eulerd","ZYZ","frame");
T = 0.5;
b = slerp(q1,q2,T);
But MATLAB returns error:
Unrecognized function or variable ‘slerp’.
When I look it up, the only posts say quaternion must be loaded, and it is indeed loaded since I can see Quaternion objects for q1 and q2. Then, I also installed navigation toolbox, but the problem remains. After installing the Sensor Fusion toolbox, Matlab reopens. I used the following code:
q1 = quaternion([75,-20,-10],"eulerd","ZYZ","frame");
q2 = quaternion([-45,20,30],"eulerd","ZYZ","frame");
T = 0.5;
b = slerp(q1,q2,T);
But MATLAB returns error:
Unrecognized function or variable ‘slerp’.
When I look it up, the only posts say quaternion must be loaded, and it is indeed loaded since I can see Quaternion objects for q1 and q2. Then, I also installed navigation toolbox, but the problem remains. toolbox, installation, slerp MATLAB Answers — New Questions
my netcdf.open can not open the url I want ;help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
error:
…
READDAP_New: did not work at 98 try: lets try again.
READDAP_New: did not work at 99 try: lets try again.
READDAP_New: did not work at 100 try: lets try again.
READDAP_New: did not work at 101 try: lets try again.
错误使用 readdap (line 45)
READDAP_New: repeated failures after 100 queries
出错 get_ECCO_subgrid (line 45)
lon=readdap(path,’LONGITUDE_T’,[]);
出错 download_ECCO (line 65)
get_ECCO_subgrid(fname,lonmin,lonmax,latmin,latmax);
出错 make_OGCM (line 122)
eval([‘download_’,OGCM,'(Ymin,Ymax,Mmin,Mmax,lonmin,lonmax,latmin,latmax,’,…
readdap (line 45):
if nargin <2
disp([‘not engough input argments’]);
elseif nargin <3 || isempty(query)
disp([‘READDAP_New: Extract : ‘, varname])
while isempty(data)
if ntry>nmax
error([‘READDAP_New: repeated failures after ‘,num2str(nmax),’ queries’])
end
ntry=ntry+1;
try
ncid = netcdf.open ( url,’NOWRITE’ );
varid = netcdf.inqVarID(ncid,varname);
data = netcdf.getVar(ncid,varid,’double’);
netcdf.close (ncid);
catch
data=[];
disp([‘READDAP_New: did not work at ‘,num2str(ntry),’ try: lets try again.’])
end
end
else
…….
the problem:error:
…
READDAP_New: did not work at 98 try: lets try again.
READDAP_New: did not work at 99 try: lets try again.
READDAP_New: did not work at 100 try: lets try again.
READDAP_New: did not work at 101 try: lets try again.
错误使用 readdap (line 45)
READDAP_New: repeated failures after 100 queries
出错 get_ECCO_subgrid (line 45)
lon=readdap(path,’LONGITUDE_T’,[]);
出错 download_ECCO (line 65)
get_ECCO_subgrid(fname,lonmin,lonmax,latmin,latmax);
出错 make_OGCM (line 122)
eval([‘download_’,OGCM,'(Ymin,Ymax,Mmin,Mmax,lonmin,lonmax,latmin,latmax,’,…
readdap (line 45):
if nargin <2
disp([‘not engough input argments’]);
elseif nargin <3 || isempty(query)
disp([‘READDAP_New: Extract : ‘, varname])
while isempty(data)
if ntry>nmax
error([‘READDAP_New: repeated failures after ‘,num2str(nmax),’ queries’])
end
ntry=ntry+1;
try
ncid = netcdf.open ( url,’NOWRITE’ );
varid = netcdf.inqVarID(ncid,varname);
data = netcdf.getVar(ncid,varid,’double’);
netcdf.close (ncid);
catch
data=[];
disp([‘READDAP_New: did not work at ‘,num2str(ntry),’ try: lets try again.’])
end
end
else
…….
the problem: error:
…
READDAP_New: did not work at 98 try: lets try again.
READDAP_New: did not work at 99 try: lets try again.
READDAP_New: did not work at 100 try: lets try again.
READDAP_New: did not work at 101 try: lets try again.
错误使用 readdap (line 45)
READDAP_New: repeated failures after 100 queries
出错 get_ECCO_subgrid (line 45)
lon=readdap(path,’LONGITUDE_T’,[]);
出错 download_ECCO (line 65)
get_ECCO_subgrid(fname,lonmin,lonmax,latmin,latmax);
出错 make_OGCM (line 122)
eval([‘download_’,OGCM,'(Ymin,Ymax,Mmin,Mmax,lonmin,lonmax,latmin,latmax,’,…
readdap (line 45):
if nargin <2
disp([‘not engough input argments’]);
elseif nargin <3 || isempty(query)
disp([‘READDAP_New: Extract : ‘, varname])
while isempty(data)
if ntry>nmax
error([‘READDAP_New: repeated failures after ‘,num2str(nmax),’ queries’])
end
ntry=ntry+1;
try
ncid = netcdf.open ( url,’NOWRITE’ );
varid = netcdf.inqVarID(ncid,varname);
data = netcdf.getVar(ncid,varid,’double’);
netcdf.close (ncid);
catch
data=[];
disp([‘READDAP_New: did not work at ‘,num2str(ntry),’ try: lets try again.’])
end
end
else
…….
the problem: netcdf.open MATLAB Answers — New Questions