Tag Archives: matlab
n-dimensional Polyhedron plotting using 2-dimensional plot commamnd
I have a 4-dimensional system with 4 states x=(x1, x2, x3,x4) as follow:
A =[ 0 1 0 0
0 -6.7811 203.43 1.6275
0 0 0 1
0 0.89105 -26.732 -6.8804];
B =[ 0
101.72
0
61.26];
xmin = [-2; -5;-4; -2];xmax = [0; 50; 10; 10];
umin =-5;umax =5;
and a I must plot a Polyhedron as follow only for x1 , x2
X = Polyhedron(‘lb’,model.x.min,’ub’,model.x.max);
above-mentionaed Polyhedron is 4-dimentional and it is not possible to plot it.
i want to plot this polyhedron in 2-dimensional page only for x1 and x2 states such that x1 state is considered as horizontal axis and x2 state is considered as vertical axis.
How can I do that in Matlab?I have a 4-dimensional system with 4 states x=(x1, x2, x3,x4) as follow:
A =[ 0 1 0 0
0 -6.7811 203.43 1.6275
0 0 0 1
0 0.89105 -26.732 -6.8804];
B =[ 0
101.72
0
61.26];
xmin = [-2; -5;-4; -2];xmax = [0; 50; 10; 10];
umin =-5;umax =5;
and a I must plot a Polyhedron as follow only for x1 , x2
X = Polyhedron(‘lb’,model.x.min,’ub’,model.x.max);
above-mentionaed Polyhedron is 4-dimentional and it is not possible to plot it.
i want to plot this polyhedron in 2-dimensional page only for x1 and x2 states such that x1 state is considered as horizontal axis and x2 state is considered as vertical axis.
How can I do that in Matlab? I have a 4-dimensional system with 4 states x=(x1, x2, x3,x4) as follow:
A =[ 0 1 0 0
0 -6.7811 203.43 1.6275
0 0 0 1
0 0.89105 -26.732 -6.8804];
B =[ 0
101.72
0
61.26];
xmin = [-2; -5;-4; -2];xmax = [0; 50; 10; 10];
umin =-5;umax =5;
and a I must plot a Polyhedron as follow only for x1 , x2
X = Polyhedron(‘lb’,model.x.min,’ub’,model.x.max);
above-mentionaed Polyhedron is 4-dimentional and it is not possible to plot it.
i want to plot this polyhedron in 2-dimensional page only for x1 and x2 states such that x1 state is considered as horizontal axis and x2 state is considered as vertical axis.
How can I do that in Matlab? polyhedron, mpc MATLAB Answers — New Questions
Cannot figure out how to fit a complicated custom equation.
I am having trouble implementing this equation into the curve fitting toolbox, both in the command and by utilizing the curve fitting GUI.
A little background that may help explain this:
I am wanting to fit experimental data of T(K) vs K_ph (W/m K) which the thermal conductivity of a material, to a model from a journal paper. I have done an okay job in python with scipy.optimize but have been trying MATLAB for a more accurate method.
I have this equation I need to fit
where
A, B, b, C_1, C_2, D, Omega_res1, Omega_res2, and L (ignore L in the exmaple code) are all coefficients I want solved for.
Omega is the independent variable in the integral (omega is solved for) while T is the range 1 to 100 in 1K steps. Or T can simply be my experimental Temperature data as is in my code.
My problems (in the GUI) are in the ways to set the values for T and use an integral in the custom equation box. As in, I am not sure how to tyep the equation in the way MATLAB accepts in the GUI for the toolbox.
My problems for the code is in the integration and lsqcurve fit it seems. I have a lot of warnings/errors such as
Warning: Derivative finite-differencing step was artificially reduced to be within bound constraints. This may
adversely affect convergence. Increasing distance between bound constraints, in dimension 6, to be at least 2e-20
may improve results.
Local minimum possible.
lsqcurvefit stopped because the size of the current step is less than
the value of the step size tolerance.
<stopping criteria details>
Fitted Parameters:
D = 1e-40
B = 1e-20
A = 1e-15
b = 100
C1 = 1e-40
C2 = 1e-40
I am not sure how to fix these, I have gone through other posts on similar matters and have changed the bounds and manually changed the optimoptions values to very low, but reached a point where it was just iterating nonstop.
Any help is appreciated!
% Data from 0T.txt
data = readmatrix(‘0T.txt’, ‘HeaderLines’, 1);
T_data = data(:, 1); % First col: Temperature (K)
k_ph_data = data(:, 2); % Second col: kappa_{xx} (W/mK)
% Constants
k_B = 1.380649e-23; % Boltzmann constant in J/K
hbar = 1.0545718e-34; % Reduced Planck constant in J·s
v_s = 4.817e3; % Sound velocity in m/s
theta_D = 235; % Debye temperature in K
L = 1e-6; % Length in m
% Define the integrand function with omega_res1 and omega_res2
integrand = @(omega, T, D, B, A, b, C1, C2, omega_res1, omega_res2) …
(omega.^4 .* exp(hbar*omega./(k_B*T)) ./ (exp(hbar*omega./(k_B*T)) – 1).^2) .* …
(v_s / L + D*omega.^4 + B*omega + A*T*omega.^3 .* exp(-theta_D / (b*T)) + …
C1 * omega.^4 ./ ((omega.^2 – omega_res1.^2).^2 + 1e-10) .* exp(-hbar*omega_res1 / (k_B * T)) ./ …
(1 + exp(-hbar*omega_res1 / (k_B * T))) + …
C2 * omega.^4 ./ ((omega.^2 – omega_res2.^2).^2 + 1e-10) .* exp(-hbar*omega_res2 / (k_B * T)) ./ …
(1 + exp(-hbar*omega_res2 / (k_B * T))));
% Define the k_ph function
k_ph_func = @(params, T) (k_B / (2 * pi^2 * v_s)) * (k_B * T / hbar)^3 .* …
integral(@(omega) integrand(omega, T, params(1), params(2), params(3), params(4), params(5), params(6), params(7), params(8)), 0, theta_D / T);
% Define the function to be minimized
fun = @(params, T) arrayfun(@(t) k_ph_func(params, t), T);
% Initial guess for parameters [D, B, A, b, C1, C2, omega_res1, omega_res2]
initial_guess = [1e-43, 1e-6, 1e-31, 1, 1e9, 1e10, 1e12, 4e12];
% Set bounds
lb = [1e-50, 1e-12, 1e-35, 1, 1e7, 1e8, 1e10, 3e12];
ub = [1e-40, 1e-3, 1e-28, 1000, 1e11, 1e12, 1e14, 5e12];
% Create opts structure
opts = optimoptions(‘lsqcurvefit’, ‘MaxFunctionEvaluations’, 1e4, ‘MaxIterations’, 1e3);
% Use lsqcurvefit for the fitting
[fitted_params, resnorm, residual, exitflag, output] = lsqcurvefit(fun, initial_guess, T_data, k_ph_data, lb, ub, opts);
% Generate fitted curve (using log spacing)
T_fit = logspace(log10(min(T_data)), log10(max(T_data)), 100);
k_ph_fit = fun(fitted_params, T_fit);I am having trouble implementing this equation into the curve fitting toolbox, both in the command and by utilizing the curve fitting GUI.
A little background that may help explain this:
I am wanting to fit experimental data of T(K) vs K_ph (W/m K) which the thermal conductivity of a material, to a model from a journal paper. I have done an okay job in python with scipy.optimize but have been trying MATLAB for a more accurate method.
I have this equation I need to fit
where
A, B, b, C_1, C_2, D, Omega_res1, Omega_res2, and L (ignore L in the exmaple code) are all coefficients I want solved for.
Omega is the independent variable in the integral (omega is solved for) while T is the range 1 to 100 in 1K steps. Or T can simply be my experimental Temperature data as is in my code.
My problems (in the GUI) are in the ways to set the values for T and use an integral in the custom equation box. As in, I am not sure how to tyep the equation in the way MATLAB accepts in the GUI for the toolbox.
My problems for the code is in the integration and lsqcurve fit it seems. I have a lot of warnings/errors such as
Warning: Derivative finite-differencing step was artificially reduced to be within bound constraints. This may
adversely affect convergence. Increasing distance between bound constraints, in dimension 6, to be at least 2e-20
may improve results.
Local minimum possible.
lsqcurvefit stopped because the size of the current step is less than
the value of the step size tolerance.
<stopping criteria details>
Fitted Parameters:
D = 1e-40
B = 1e-20
A = 1e-15
b = 100
C1 = 1e-40
C2 = 1e-40
I am not sure how to fix these, I have gone through other posts on similar matters and have changed the bounds and manually changed the optimoptions values to very low, but reached a point where it was just iterating nonstop.
Any help is appreciated!
% Data from 0T.txt
data = readmatrix(‘0T.txt’, ‘HeaderLines’, 1);
T_data = data(:, 1); % First col: Temperature (K)
k_ph_data = data(:, 2); % Second col: kappa_{xx} (W/mK)
% Constants
k_B = 1.380649e-23; % Boltzmann constant in J/K
hbar = 1.0545718e-34; % Reduced Planck constant in J·s
v_s = 4.817e3; % Sound velocity in m/s
theta_D = 235; % Debye temperature in K
L = 1e-6; % Length in m
% Define the integrand function with omega_res1 and omega_res2
integrand = @(omega, T, D, B, A, b, C1, C2, omega_res1, omega_res2) …
(omega.^4 .* exp(hbar*omega./(k_B*T)) ./ (exp(hbar*omega./(k_B*T)) – 1).^2) .* …
(v_s / L + D*omega.^4 + B*omega + A*T*omega.^3 .* exp(-theta_D / (b*T)) + …
C1 * omega.^4 ./ ((omega.^2 – omega_res1.^2).^2 + 1e-10) .* exp(-hbar*omega_res1 / (k_B * T)) ./ …
(1 + exp(-hbar*omega_res1 / (k_B * T))) + …
C2 * omega.^4 ./ ((omega.^2 – omega_res2.^2).^2 + 1e-10) .* exp(-hbar*omega_res2 / (k_B * T)) ./ …
(1 + exp(-hbar*omega_res2 / (k_B * T))));
% Define the k_ph function
k_ph_func = @(params, T) (k_B / (2 * pi^2 * v_s)) * (k_B * T / hbar)^3 .* …
integral(@(omega) integrand(omega, T, params(1), params(2), params(3), params(4), params(5), params(6), params(7), params(8)), 0, theta_D / T);
% Define the function to be minimized
fun = @(params, T) arrayfun(@(t) k_ph_func(params, t), T);
% Initial guess for parameters [D, B, A, b, C1, C2, omega_res1, omega_res2]
initial_guess = [1e-43, 1e-6, 1e-31, 1, 1e9, 1e10, 1e12, 4e12];
% Set bounds
lb = [1e-50, 1e-12, 1e-35, 1, 1e7, 1e8, 1e10, 3e12];
ub = [1e-40, 1e-3, 1e-28, 1000, 1e11, 1e12, 1e14, 5e12];
% Create opts structure
opts = optimoptions(‘lsqcurvefit’, ‘MaxFunctionEvaluations’, 1e4, ‘MaxIterations’, 1e3);
% Use lsqcurvefit for the fitting
[fitted_params, resnorm, residual, exitflag, output] = lsqcurvefit(fun, initial_guess, T_data, k_ph_data, lb, ub, opts);
% Generate fitted curve (using log spacing)
T_fit = logspace(log10(min(T_data)), log10(max(T_data)), 100);
k_ph_fit = fun(fitted_params, T_fit); I am having trouble implementing this equation into the curve fitting toolbox, both in the command and by utilizing the curve fitting GUI.
A little background that may help explain this:
I am wanting to fit experimental data of T(K) vs K_ph (W/m K) which the thermal conductivity of a material, to a model from a journal paper. I have done an okay job in python with scipy.optimize but have been trying MATLAB for a more accurate method.
I have this equation I need to fit
where
A, B, b, C_1, C_2, D, Omega_res1, Omega_res2, and L (ignore L in the exmaple code) are all coefficients I want solved for.
Omega is the independent variable in the integral (omega is solved for) while T is the range 1 to 100 in 1K steps. Or T can simply be my experimental Temperature data as is in my code.
My problems (in the GUI) are in the ways to set the values for T and use an integral in the custom equation box. As in, I am not sure how to tyep the equation in the way MATLAB accepts in the GUI for the toolbox.
My problems for the code is in the integration and lsqcurve fit it seems. I have a lot of warnings/errors such as
Warning: Derivative finite-differencing step was artificially reduced to be within bound constraints. This may
adversely affect convergence. Increasing distance between bound constraints, in dimension 6, to be at least 2e-20
may improve results.
Local minimum possible.
lsqcurvefit stopped because the size of the current step is less than
the value of the step size tolerance.
<stopping criteria details>
Fitted Parameters:
D = 1e-40
B = 1e-20
A = 1e-15
b = 100
C1 = 1e-40
C2 = 1e-40
I am not sure how to fix these, I have gone through other posts on similar matters and have changed the bounds and manually changed the optimoptions values to very low, but reached a point where it was just iterating nonstop.
Any help is appreciated!
% Data from 0T.txt
data = readmatrix(‘0T.txt’, ‘HeaderLines’, 1);
T_data = data(:, 1); % First col: Temperature (K)
k_ph_data = data(:, 2); % Second col: kappa_{xx} (W/mK)
% Constants
k_B = 1.380649e-23; % Boltzmann constant in J/K
hbar = 1.0545718e-34; % Reduced Planck constant in J·s
v_s = 4.817e3; % Sound velocity in m/s
theta_D = 235; % Debye temperature in K
L = 1e-6; % Length in m
% Define the integrand function with omega_res1 and omega_res2
integrand = @(omega, T, D, B, A, b, C1, C2, omega_res1, omega_res2) …
(omega.^4 .* exp(hbar*omega./(k_B*T)) ./ (exp(hbar*omega./(k_B*T)) – 1).^2) .* …
(v_s / L + D*omega.^4 + B*omega + A*T*omega.^3 .* exp(-theta_D / (b*T)) + …
C1 * omega.^4 ./ ((omega.^2 – omega_res1.^2).^2 + 1e-10) .* exp(-hbar*omega_res1 / (k_B * T)) ./ …
(1 + exp(-hbar*omega_res1 / (k_B * T))) + …
C2 * omega.^4 ./ ((omega.^2 – omega_res2.^2).^2 + 1e-10) .* exp(-hbar*omega_res2 / (k_B * T)) ./ …
(1 + exp(-hbar*omega_res2 / (k_B * T))));
% Define the k_ph function
k_ph_func = @(params, T) (k_B / (2 * pi^2 * v_s)) * (k_B * T / hbar)^3 .* …
integral(@(omega) integrand(omega, T, params(1), params(2), params(3), params(4), params(5), params(6), params(7), params(8)), 0, theta_D / T);
% Define the function to be minimized
fun = @(params, T) arrayfun(@(t) k_ph_func(params, t), T);
% Initial guess for parameters [D, B, A, b, C1, C2, omega_res1, omega_res2]
initial_guess = [1e-43, 1e-6, 1e-31, 1, 1e9, 1e10, 1e12, 4e12];
% Set bounds
lb = [1e-50, 1e-12, 1e-35, 1, 1e7, 1e8, 1e10, 3e12];
ub = [1e-40, 1e-3, 1e-28, 1000, 1e11, 1e12, 1e14, 5e12];
% Create opts structure
opts = optimoptions(‘lsqcurvefit’, ‘MaxFunctionEvaluations’, 1e4, ‘MaxIterations’, 1e3);
% Use lsqcurvefit for the fitting
[fitted_params, resnorm, residual, exitflag, output] = lsqcurvefit(fun, initial_guess, T_data, k_ph_data, lb, ub, opts);
% Generate fitted curve (using log spacing)
T_fit = logspace(log10(min(T_data)), log10(max(T_data)), 100);
k_ph_fit = fun(fitted_params, T_fit); curve fitting MATLAB Answers — New Questions
extract 1 row data of 1 table
I want to extract the data of a row in a table, how to do it
exam: Name address age
hang VN 18
nam vn 40
lan vn 23
I want to retrieve the information of a man named Nam
help me!I want to extract the data of a row in a table, how to do it
exam: Name address age
hang VN 18
nam vn 40
lan vn 23
I want to retrieve the information of a man named Nam
help me! I want to extract the data of a row in a table, how to do it
exam: Name address age
hang VN 18
nam vn 40
lan vn 23
I want to retrieve the information of a man named Nam
help me! extract 1 row data of 1 table MATLAB Answers — New Questions
custom phase changing material does not release heat.
Problem:
When I adjust the latent heat, there’s no change in the temperature curve of the XPS material. I anticipate a stable temperature, ranging between 305K and 320K. So the problem is that the material does not release the absorbed heat.
equations
assert(Cps > 0 && Cpl > 0)
assert(T > 0, ‘Temperature must be greater than absolute zero’)
T == M.T;
if T >= Tmelt_start && T <= Tmelt_end
phaseChangeRate == {0.001, ‘1/s’};
else
phaseChangeRate == {0, ‘1/s’};
end
if phase < 1 && phase > 0
Q == m * Cps * T.der + m * L * phaseChangeRate;
phase.der == phaseChangeRate;
else
Q == m * Cpl * T.der;
phase.der == {0, ‘1/s’};
end
end
explanation of the full code:
This code describes a thermal component that models internal energy storage in a thermal network. Here’s a breakdown of the main parts of this code:
1. **Nodes**: These are points where other components can connect. Two thermal nodes are defined: `M` (top) and `N` (bottom).
2. **Inputs**: These values can be supplied from outside. `Mdot` represents the mass flow rate (in kg/s) and `T_in` is the input temperature (in Kelvin).
3. **Parameters**: These values determine the behavior of the component. They include:
– `mass_type`: Type of mass (constant or variable).
– `mass`: The mass of the thermal component.
– `Cps` and `Cpl`: Specific heat capacity for solid and liquid, respectively.
– `Tmelt_start` and `Tmelt_end`: The temperature range where the material starts melting and stops melting.
– `L`: Specific latent heat.
– `mass_min`: Minimum mass.
– `num_ports`: The number of graphical ports.
4. **Annotations**: These are metadata that provide additional information about the component or dictate how it is displayed in a GUI. Here, it is primarily used to indicate which parameters can be modified externally and to define the component’s icon.
5. **Variables**: These represent the internal states of the component. They include:
– `m`: The mass.
– `T`: The temperature.
– `phase`: The phase (0 for solid, 1 for liquid, and values in between for a mixed phase).
– `phaseChangeRate`: The rate of phase change.
– `Q`: Heat flow rate.
6. **Branches**: These are connections between different parts of the network. Here, the heat flow `Q` from node `M` to another part of the network is defined.
7. **Equations**: These describe the mathematical relationships between the different variables and parameters. They include:
– Relationships between `T`, `Q`, `m`, and other variables, especially around phase change.
– Constraints on certain values (like that `Cps`, `Cpl`, and `T` must be positive).
8. **Connections**: These are the actual connections between the different nodes within the component. Here, node `M` is connected to node `N`.
The essence of this component is that it models a thermal mass that can store and release energy. It also accounts for phase changes, meaning it can melt or solidify within a certain temperature range.
component derdecomponent
% Thermal Mass
% This block models internal energy storage in a thermal network.
nodes
M = foundation.thermal.thermal; % :top
end
inputs(ExternalAccess = none)
Mdot = {0, ‘kg/s’}; % Mdot:bottom
T_in = {300, ‘K’}; % Tin:bottom
end
nodes(ExternalAccess = none)
N = foundation.thermal.thermal; % :bottom
end
parameters
mass_type = foundation.enum.constant_variable.constant; % Mass type
end
parameters (ExternalAccess = none)
mass = {1, ‘kg’}; % Mass
end
parameters
Cps = {200, ‘J/(kg*K)’}; % Specific heat solid
Cpl = {1000, ‘J/(kg*K)’}; % Specific heat liquid
Tmelt_start = {320, ‘K’}; % Start Melting Temperature
Tmelt_end = {305, ‘K’}; % End Melting Temperature
L = {100, ‘J/(kg)’}; % Specific Latent Heat
end
parameters (ExternalAccess = none)
mass_min = {1e-6,’kg’}; % Minimum mass
end
parameters
num_ports = foundation.enum.numPorts2.one; % Number of graphical ports
end
if num_ports == 2
annotations
N : ExternalAccess=modify
end
if mass_type == foundation.enum.constant_variable.constant
annotations
% Icon = ‘mass2.svg’
end
else
annotations
% Icon = ‘mass4.svg’
end
end
else
if mass_type == foundation.enum.constant_variable.variable
annotations
% Icon = ‘mass3.svg’
end
end
end
if mass_type == foundation.enum.constant_variable.constant
annotations
mass : ExternalAccess=modify
end
equations
m == {1,’kg’};
end
else
annotations
[Mdot, T_in, m, mass_min] : ExternalAccess=modify
end
equations
assert(mass_min > 0)
end
end
variables (ExternalAccess=none)
m = {value = {1,’kg’}, priority=priority.high}; % Mass
end
variables
T = {value = {300, ‘K’}, priority = priority.high}; % Temperature
phase = {value = {0, ‘1’}, priority = priority.high}; % Phase
phaseChangeRate = {0, ‘1/s’}; % Rate of phase change
end
variables (Access=private)
Q = {0, ‘W’}; % Heat flow rate
end
branches
Q : M.Q -> *;
end
equations
assert(Cps > 0 && Cpl > 0)
assert(T > 0, ‘Temperature must be greater than absolute zero’)
T == M.T;
if T >= Tmelt_start && T <= Tmelt_end
phaseChangeRate == {0.001, ‘1/s’};
else
phaseChangeRate == {0, ‘1/s’};
end
if phase < 1 && phase > 0
Q == m * Cps * T.der + m * L * phaseChangeRate;
phase.der == phaseChangeRate;
else
Q == m * Cpl * T.der;
phase.der == {0, ‘1/s’};
end
end
connections
connect(M,N)
end
endProblem:
When I adjust the latent heat, there’s no change in the temperature curve of the XPS material. I anticipate a stable temperature, ranging between 305K and 320K. So the problem is that the material does not release the absorbed heat.
equations
assert(Cps > 0 && Cpl > 0)
assert(T > 0, ‘Temperature must be greater than absolute zero’)
T == M.T;
if T >= Tmelt_start && T <= Tmelt_end
phaseChangeRate == {0.001, ‘1/s’};
else
phaseChangeRate == {0, ‘1/s’};
end
if phase < 1 && phase > 0
Q == m * Cps * T.der + m * L * phaseChangeRate;
phase.der == phaseChangeRate;
else
Q == m * Cpl * T.der;
phase.der == {0, ‘1/s’};
end
end
explanation of the full code:
This code describes a thermal component that models internal energy storage in a thermal network. Here’s a breakdown of the main parts of this code:
1. **Nodes**: These are points where other components can connect. Two thermal nodes are defined: `M` (top) and `N` (bottom).
2. **Inputs**: These values can be supplied from outside. `Mdot` represents the mass flow rate (in kg/s) and `T_in` is the input temperature (in Kelvin).
3. **Parameters**: These values determine the behavior of the component. They include:
– `mass_type`: Type of mass (constant or variable).
– `mass`: The mass of the thermal component.
– `Cps` and `Cpl`: Specific heat capacity for solid and liquid, respectively.
– `Tmelt_start` and `Tmelt_end`: The temperature range where the material starts melting and stops melting.
– `L`: Specific latent heat.
– `mass_min`: Minimum mass.
– `num_ports`: The number of graphical ports.
4. **Annotations**: These are metadata that provide additional information about the component or dictate how it is displayed in a GUI. Here, it is primarily used to indicate which parameters can be modified externally and to define the component’s icon.
5. **Variables**: These represent the internal states of the component. They include:
– `m`: The mass.
– `T`: The temperature.
– `phase`: The phase (0 for solid, 1 for liquid, and values in between for a mixed phase).
– `phaseChangeRate`: The rate of phase change.
– `Q`: Heat flow rate.
6. **Branches**: These are connections between different parts of the network. Here, the heat flow `Q` from node `M` to another part of the network is defined.
7. **Equations**: These describe the mathematical relationships between the different variables and parameters. They include:
– Relationships between `T`, `Q`, `m`, and other variables, especially around phase change.
– Constraints on certain values (like that `Cps`, `Cpl`, and `T` must be positive).
8. **Connections**: These are the actual connections between the different nodes within the component. Here, node `M` is connected to node `N`.
The essence of this component is that it models a thermal mass that can store and release energy. It also accounts for phase changes, meaning it can melt or solidify within a certain temperature range.
component derdecomponent
% Thermal Mass
% This block models internal energy storage in a thermal network.
nodes
M = foundation.thermal.thermal; % :top
end
inputs(ExternalAccess = none)
Mdot = {0, ‘kg/s’}; % Mdot:bottom
T_in = {300, ‘K’}; % Tin:bottom
end
nodes(ExternalAccess = none)
N = foundation.thermal.thermal; % :bottom
end
parameters
mass_type = foundation.enum.constant_variable.constant; % Mass type
end
parameters (ExternalAccess = none)
mass = {1, ‘kg’}; % Mass
end
parameters
Cps = {200, ‘J/(kg*K)’}; % Specific heat solid
Cpl = {1000, ‘J/(kg*K)’}; % Specific heat liquid
Tmelt_start = {320, ‘K’}; % Start Melting Temperature
Tmelt_end = {305, ‘K’}; % End Melting Temperature
L = {100, ‘J/(kg)’}; % Specific Latent Heat
end
parameters (ExternalAccess = none)
mass_min = {1e-6,’kg’}; % Minimum mass
end
parameters
num_ports = foundation.enum.numPorts2.one; % Number of graphical ports
end
if num_ports == 2
annotations
N : ExternalAccess=modify
end
if mass_type == foundation.enum.constant_variable.constant
annotations
% Icon = ‘mass2.svg’
end
else
annotations
% Icon = ‘mass4.svg’
end
end
else
if mass_type == foundation.enum.constant_variable.variable
annotations
% Icon = ‘mass3.svg’
end
end
end
if mass_type == foundation.enum.constant_variable.constant
annotations
mass : ExternalAccess=modify
end
equations
m == {1,’kg’};
end
else
annotations
[Mdot, T_in, m, mass_min] : ExternalAccess=modify
end
equations
assert(mass_min > 0)
end
end
variables (ExternalAccess=none)
m = {value = {1,’kg’}, priority=priority.high}; % Mass
end
variables
T = {value = {300, ‘K’}, priority = priority.high}; % Temperature
phase = {value = {0, ‘1’}, priority = priority.high}; % Phase
phaseChangeRate = {0, ‘1/s’}; % Rate of phase change
end
variables (Access=private)
Q = {0, ‘W’}; % Heat flow rate
end
branches
Q : M.Q -> *;
end
equations
assert(Cps > 0 && Cpl > 0)
assert(T > 0, ‘Temperature must be greater than absolute zero’)
T == M.T;
if T >= Tmelt_start && T <= Tmelt_end
phaseChangeRate == {0.001, ‘1/s’};
else
phaseChangeRate == {0, ‘1/s’};
end
if phase < 1 && phase > 0
Q == m * Cps * T.der + m * L * phaseChangeRate;
phase.der == phaseChangeRate;
else
Q == m * Cpl * T.der;
phase.der == {0, ‘1/s’};
end
end
connections
connect(M,N)
end
end Problem:
When I adjust the latent heat, there’s no change in the temperature curve of the XPS material. I anticipate a stable temperature, ranging between 305K and 320K. So the problem is that the material does not release the absorbed heat.
equations
assert(Cps > 0 && Cpl > 0)
assert(T > 0, ‘Temperature must be greater than absolute zero’)
T == M.T;
if T >= Tmelt_start && T <= Tmelt_end
phaseChangeRate == {0.001, ‘1/s’};
else
phaseChangeRate == {0, ‘1/s’};
end
if phase < 1 && phase > 0
Q == m * Cps * T.der + m * L * phaseChangeRate;
phase.der == phaseChangeRate;
else
Q == m * Cpl * T.der;
phase.der == {0, ‘1/s’};
end
end
explanation of the full code:
This code describes a thermal component that models internal energy storage in a thermal network. Here’s a breakdown of the main parts of this code:
1. **Nodes**: These are points where other components can connect. Two thermal nodes are defined: `M` (top) and `N` (bottom).
2. **Inputs**: These values can be supplied from outside. `Mdot` represents the mass flow rate (in kg/s) and `T_in` is the input temperature (in Kelvin).
3. **Parameters**: These values determine the behavior of the component. They include:
– `mass_type`: Type of mass (constant or variable).
– `mass`: The mass of the thermal component.
– `Cps` and `Cpl`: Specific heat capacity for solid and liquid, respectively.
– `Tmelt_start` and `Tmelt_end`: The temperature range where the material starts melting and stops melting.
– `L`: Specific latent heat.
– `mass_min`: Minimum mass.
– `num_ports`: The number of graphical ports.
4. **Annotations**: These are metadata that provide additional information about the component or dictate how it is displayed in a GUI. Here, it is primarily used to indicate which parameters can be modified externally and to define the component’s icon.
5. **Variables**: These represent the internal states of the component. They include:
– `m`: The mass.
– `T`: The temperature.
– `phase`: The phase (0 for solid, 1 for liquid, and values in between for a mixed phase).
– `phaseChangeRate`: The rate of phase change.
– `Q`: Heat flow rate.
6. **Branches**: These are connections between different parts of the network. Here, the heat flow `Q` from node `M` to another part of the network is defined.
7. **Equations**: These describe the mathematical relationships between the different variables and parameters. They include:
– Relationships between `T`, `Q`, `m`, and other variables, especially around phase change.
– Constraints on certain values (like that `Cps`, `Cpl`, and `T` must be positive).
8. **Connections**: These are the actual connections between the different nodes within the component. Here, node `M` is connected to node `N`.
The essence of this component is that it models a thermal mass that can store and release energy. It also accounts for phase changes, meaning it can melt or solidify within a certain temperature range.
component derdecomponent
% Thermal Mass
% This block models internal energy storage in a thermal network.
nodes
M = foundation.thermal.thermal; % :top
end
inputs(ExternalAccess = none)
Mdot = {0, ‘kg/s’}; % Mdot:bottom
T_in = {300, ‘K’}; % Tin:bottom
end
nodes(ExternalAccess = none)
N = foundation.thermal.thermal; % :bottom
end
parameters
mass_type = foundation.enum.constant_variable.constant; % Mass type
end
parameters (ExternalAccess = none)
mass = {1, ‘kg’}; % Mass
end
parameters
Cps = {200, ‘J/(kg*K)’}; % Specific heat solid
Cpl = {1000, ‘J/(kg*K)’}; % Specific heat liquid
Tmelt_start = {320, ‘K’}; % Start Melting Temperature
Tmelt_end = {305, ‘K’}; % End Melting Temperature
L = {100, ‘J/(kg)’}; % Specific Latent Heat
end
parameters (ExternalAccess = none)
mass_min = {1e-6,’kg’}; % Minimum mass
end
parameters
num_ports = foundation.enum.numPorts2.one; % Number of graphical ports
end
if num_ports == 2
annotations
N : ExternalAccess=modify
end
if mass_type == foundation.enum.constant_variable.constant
annotations
% Icon = ‘mass2.svg’
end
else
annotations
% Icon = ‘mass4.svg’
end
end
else
if mass_type == foundation.enum.constant_variable.variable
annotations
% Icon = ‘mass3.svg’
end
end
end
if mass_type == foundation.enum.constant_variable.constant
annotations
mass : ExternalAccess=modify
end
equations
m == {1,’kg’};
end
else
annotations
[Mdot, T_in, m, mass_min] : ExternalAccess=modify
end
equations
assert(mass_min > 0)
end
end
variables (ExternalAccess=none)
m = {value = {1,’kg’}, priority=priority.high}; % Mass
end
variables
T = {value = {300, ‘K’}, priority = priority.high}; % Temperature
phase = {value = {0, ‘1’}, priority = priority.high}; % Phase
phaseChangeRate = {0, ‘1/s’}; % Rate of phase change
end
variables (Access=private)
Q = {0, ‘W’}; % Heat flow rate
end
branches
Q : M.Q -> *;
end
equations
assert(Cps > 0 && Cpl > 0)
assert(T > 0, ‘Temperature must be greater than absolute zero’)
T == M.T;
if T >= Tmelt_start && T <= Tmelt_end
phaseChangeRate == {0.001, ‘1/s’};
else
phaseChangeRate == {0, ‘1/s’};
end
if phase < 1 && phase > 0
Q == m * Cps * T.der + m * L * phaseChangeRate;
phase.der == phaseChangeRate;
else
Q == m * Cpl * T.der;
phase.der == {0, ‘1/s’};
end
end
connections
connect(M,N)
end
end phasechangingmaterial, heattransfer MATLAB Answers — New Questions
Simulink zoom / scroll problem on MacBook Pro trackpad
When I two-finger scroll on my trackpad to zoom a Simulink model, it
zooms in and out rapidly and erratically. Moreoever, pinch-to-zoom
produces no zooming effect.
This problem was noted here:
http://lizard-spock.co.uk/blog/engineering/simulink-scroll-wheel-erratic-behaviour/
They advised disabling scroll-wheel zoom altogether with
File > Simulink Prefs > Editor defaults > Scroll wheel controls zooming preference.
However, the zoom feature is essential for fast model navigation.
I have tried twiddling various settings on the Mac Trackpad system preferences, no luck.
The following Mathworks doc claims that pinch-to-zoom and regular
scroll-zoom should work, but it doesn’t for me.
http://www.mathworks.com/help/simulink/ug/zooming-block-diagrams.html
Has anyone solved this?
("Use a mouse" and "just click the zoom button" are not acceptable
answers, since I don’t want to lug a mouse around just for Matlab and
having to click a button is a crappy UI constraint on something that
should be natural.)
Thanks for your help.When I two-finger scroll on my trackpad to zoom a Simulink model, it
zooms in and out rapidly and erratically. Moreoever, pinch-to-zoom
produces no zooming effect.
This problem was noted here:
http://lizard-spock.co.uk/blog/engineering/simulink-scroll-wheel-erratic-behaviour/
They advised disabling scroll-wheel zoom altogether with
File > Simulink Prefs > Editor defaults > Scroll wheel controls zooming preference.
However, the zoom feature is essential for fast model navigation.
I have tried twiddling various settings on the Mac Trackpad system preferences, no luck.
The following Mathworks doc claims that pinch-to-zoom and regular
scroll-zoom should work, but it doesn’t for me.
http://www.mathworks.com/help/simulink/ug/zooming-block-diagrams.html
Has anyone solved this?
("Use a mouse" and "just click the zoom button" are not acceptable
answers, since I don’t want to lug a mouse around just for Matlab and
having to click a button is a crappy UI constraint on something that
should be natural.)
Thanks for your help. When I two-finger scroll on my trackpad to zoom a Simulink model, it
zooms in and out rapidly and erratically. Moreoever, pinch-to-zoom
produces no zooming effect.
This problem was noted here:
http://lizard-spock.co.uk/blog/engineering/simulink-scroll-wheel-erratic-behaviour/
They advised disabling scroll-wheel zoom altogether with
File > Simulink Prefs > Editor defaults > Scroll wheel controls zooming preference.
However, the zoom feature is essential for fast model navigation.
I have tried twiddling various settings on the Mac Trackpad system preferences, no luck.
The following Mathworks doc claims that pinch-to-zoom and regular
scroll-zoom should work, but it doesn’t for me.
http://www.mathworks.com/help/simulink/ug/zooming-block-diagrams.html
Has anyone solved this?
("Use a mouse" and "just click the zoom button" are not acceptable
answers, since I don’t want to lug a mouse around just for Matlab and
having to click a button is a crappy UI constraint on something that
should be natural.)
Thanks for your help. simulink, trackpad, zoom MATLAB Answers — New Questions
Compiling error : Unknown file extension ‘ ‘
I am compiling a file that contains a caller block, and that c caller block is calling c file that have many header files included. But while compiling its giving error Unknown "file extension ‘ ‘ ". Can anyone tell me how to solve this one?I am compiling a file that contains a caller block, and that c caller block is calling c file that have many header files included. But while compiling its giving error Unknown "file extension ‘ ‘ ". Can anyone tell me how to solve this one? I am compiling a file that contains a caller block, and that c caller block is calling c file that have many header files included. But while compiling its giving error Unknown "file extension ‘ ‘ ". Can anyone tell me how to solve this one? c caller, mex, error, unknown file MATLAB Answers — New Questions
Looking to License two separate Programs PolySpace on one port and Matlab on a separate one.
I have licensing in an offline environment. One for Matlab and one for POLLSPACE. I’m looking to license them both on the same server (since both licenses have that MAC:ID tied to them). I’m running into the fact that I can’t run two separate MLM.exe’s on the same FLEXNet license manager. So my thought was I could combine the licensing that is for the same server ID, for the two products. But I seem to be running into and issue that I don’t know how to make it so both products are working and on separate ports.
Is there a way either in options file or something similar to be able to take two valid licenses and have the products be listening on two separate ports?
Thanks!I have licensing in an offline environment. One for Matlab and one for POLLSPACE. I’m looking to license them both on the same server (since both licenses have that MAC:ID tied to them). I’m running into the fact that I can’t run two separate MLM.exe’s on the same FLEXNet license manager. So my thought was I could combine the licensing that is for the same server ID, for the two products. But I seem to be running into and issue that I don’t know how to make it so both products are working and on separate ports.
Is there a way either in options file or something similar to be able to take two valid licenses and have the products be listening on two separate ports?
Thanks! I have licensing in an offline environment. One for Matlab and one for POLLSPACE. I’m looking to license them both on the same server (since both licenses have that MAC:ID tied to them). I’m running into the fact that I can’t run two separate MLM.exe’s on the same FLEXNet license manager. So my thought was I could combine the licensing that is for the same server ID, for the two products. But I seem to be running into and issue that I don’t know how to make it so both products are working and on separate ports.
Is there a way either in options file or something similar to be able to take two valid licenses and have the products be listening on two separate ports?
Thanks! license, licensemanager MATLAB Answers — New Questions
Finding mean value over certain amount of values in a matrix
Hello!
I would like to calculate the mean value of a defined number of values of the columns in a matrix.
e.g.
Mean value every 2 values column by column of A.
A = [1,2,3;4,6,8;7,12,7;14,4,23];
result = [2.5,4,5.5;10.5,8,15]
Thanks for the answers in advance.Hello!
I would like to calculate the mean value of a defined number of values of the columns in a matrix.
e.g.
Mean value every 2 values column by column of A.
A = [1,2,3;4,6,8;7,12,7;14,4,23];
result = [2.5,4,5.5;10.5,8,15]
Thanks for the answers in advance. Hello!
I would like to calculate the mean value of a defined number of values of the columns in a matrix.
e.g.
Mean value every 2 values column by column of A.
A = [1,2,3;4,6,8;7,12,7;14,4,23];
result = [2.5,4,5.5;10.5,8,15]
Thanks for the answers in advance. mean, matlab, reshape MATLAB Answers — New Questions
How to deal with MISRA SLSF 036 rule
Hello,
I’m using Simulink and Stateflow to produce a MISRA SLSF and MISRA C compliant model, to produce an AUTOSAR SwC with Embedded Coder.
I’m using bus signals into models in different points as they are really useful for my intended implementation.
One of the required rules by MISRA SLSF is the 036. The statement "A" of this rule suggest not to use Bus inputs with Stateflow, since buses are used in Simulink to package signals together often with different types. Each data in Stateflow must have a unique type definition.
My questions are:
– Is this rule still valid with R2018a?
– Is there a correlated check into Model Advisor for this rule?
– Is there a way to use buses and respect this rule?
Thanks in advanceHello,
I’m using Simulink and Stateflow to produce a MISRA SLSF and MISRA C compliant model, to produce an AUTOSAR SwC with Embedded Coder.
I’m using bus signals into models in different points as they are really useful for my intended implementation.
One of the required rules by MISRA SLSF is the 036. The statement "A" of this rule suggest not to use Bus inputs with Stateflow, since buses are used in Simulink to package signals together often with different types. Each data in Stateflow must have a unique type definition.
My questions are:
– Is this rule still valid with R2018a?
– Is there a correlated check into Model Advisor for this rule?
– Is there a way to use buses and respect this rule?
Thanks in advance Hello,
I’m using Simulink and Stateflow to produce a MISRA SLSF and MISRA C compliant model, to produce an AUTOSAR SwC with Embedded Coder.
I’m using bus signals into models in different points as they are really useful for my intended implementation.
One of the required rules by MISRA SLSF is the 036. The statement "A" of this rule suggest not to use Bus inputs with Stateflow, since buses are used in Simulink to package signals together often with different types. Each data in Stateflow must have a unique type definition.
My questions are:
– Is this rule still valid with R2018a?
– Is there a correlated check into Model Advisor for this rule?
– Is there a way to use buses and respect this rule?
Thanks in advance stateflow, misra MATLAB Answers — New Questions
How to you the output of gnssBitSynchronize to increase integration time of PLL?
Hello, I have been checking and trying the GPS data decode example found in this link:
https://www.mathworks.com/help/satcom/ug/gps-data-decode.html
At the end of the example, it includes a further exploration which says that:
"Also, this example does not update the bit synchronization status back to the tracking loop. You can also use the bit synchronization value to increase the phase locked loop (PLL) integration time to enhance the PLL performance at low SNR values"
I am interested to do and apply this in the GPS Software receiver I am using. Is the sync index the location of start of navigation data bit? how do I use this to increase the PLL integration time?
Thank you for your help.Hello, I have been checking and trying the GPS data decode example found in this link:
https://www.mathworks.com/help/satcom/ug/gps-data-decode.html
At the end of the example, it includes a further exploration which says that:
"Also, this example does not update the bit synchronization status back to the tracking loop. You can also use the bit synchronization value to increase the phase locked loop (PLL) integration time to enhance the PLL performance at low SNR values"
I am interested to do and apply this in the GPS Software receiver I am using. Is the sync index the location of start of navigation data bit? how do I use this to increase the PLL integration time?
Thank you for your help. Hello, I have been checking and trying the GPS data decode example found in this link:
https://www.mathworks.com/help/satcom/ug/gps-data-decode.html
At the end of the example, it includes a further exploration which says that:
"Also, this example does not update the bit synchronization status back to the tracking loop. You can also use the bit synchronization value to increase the phase locked loop (PLL) integration time to enhance the PLL performance at low SNR values"
I am interested to do and apply this in the GPS Software receiver I am using. Is the sync index the location of start of navigation data bit? how do I use this to increase the PLL integration time?
Thank you for your help. gps MATLAB Answers — New Questions
Simscape Onramp Section 8.1 Task 9
I don’t know how to Solve this problem. There is no hint and solution.I don’t know how to Solve this problem. There is no hint and solution. I don’t know how to Solve this problem. There is no hint and solution. simscape MATLAB Answers — New Questions
I made a Heat map. I want to remove the x and y axis ticks. How is that possible?
I tried using set(gca…………), but that is for plot. i am stuck at this.I tried using set(gca…………), but that is for plot. i am stuck at this. I tried using set(gca…………), but that is for plot. i am stuck at this. heatmap, colormap MATLAB Answers — New Questions
draw the centered data on the same axes as the raw data
draw the centered data on the same axes as the raw data given 12 samples of the raw data
WireLength DieHeight
1 125
4 110
5 287
6 200
8 350
10 280
12 400
14 370
13 480
18 420
19 540
22 518
where WireLength is the x axis and Die Height is the y axisdraw the centered data on the same axes as the raw data given 12 samples of the raw data
WireLength DieHeight
1 125
4 110
5 287
6 200
8 350
10 280
12 400
14 370
13 480
18 420
19 540
22 518
where WireLength is the x axis and Die Height is the y axis draw the centered data on the same axes as the raw data given 12 samples of the raw data
WireLength DieHeight
1 125
4 110
5 287
6 200
8 350
10 280
12 400
14 370
13 480
18 420
19 540
22 518
where WireLength is the x axis and Die Height is the y axis scatter, centered d MATLAB Answers — New Questions
How to load data from a .txt file to matlab in the form of a matrix???
I am saving data in a .txt file from c++ code which is continuously updating in real time.can i get this real time data loaded in to matrix in matlab in real time?? Please helpI am saving data in a .txt file from c++ code which is continuously updating in real time.can i get this real time data loaded in to matrix in matlab in real time?? Please help I am saving data in a .txt file from c++ code which is continuously updating in real time.can i get this real time data loaded in to matrix in matlab in real time?? Please help export MATLAB Answers — New Questions
How to PLOT from .TRC file generated by keysight N9320B Spectrum analyzer
I am trying to generate the plot from Keysight N9320 Spectrum analyzer .trc file from https://www.mathworks.com/matlabcentral/fileexchange/22908-read-spectrum-analyzer-trace-file but MATLAB can’t read it and error is
Unrecognized field name "XStart".
Error in readsatf (line 139)
freq(index) = struct.XStart + (index-1)*struct.XScale/struct.XNum;
because file don’t contain "#" headers and all the data is unreadable is there any other way to access these results from the .trc file.I am trying to generate the plot from Keysight N9320 Spectrum analyzer .trc file from https://www.mathworks.com/matlabcentral/fileexchange/22908-read-spectrum-analyzer-trace-file but MATLAB can’t read it and error is
Unrecognized field name "XStart".
Error in readsatf (line 139)
freq(index) = struct.XStart + (index-1)*struct.XScale/struct.XNum;
because file don’t contain "#" headers and all the data is unreadable is there any other way to access these results from the .trc file. I am trying to generate the plot from Keysight N9320 Spectrum analyzer .trc file from https://www.mathworks.com/matlabcentral/fileexchange/22908-read-spectrum-analyzer-trace-file but MATLAB can’t read it and error is
Unrecognized field name "XStart".
Error in readsatf (line 139)
freq(index) = struct.XStart + (index-1)*struct.XScale/struct.XNum;
because file don’t contain "#" headers and all the data is unreadable is there any other way to access these results from the .trc file. keysight, n8320b spectrum analyzer MATLAB Answers — New Questions
The dofference of predict() and PredictAndUpdateState()
Hi All,
I found the following two ways of predicting performs differently:
(1).
for i=1:size(XTest,2)
[trainedNet,YTest(:,i)]=PredictAndUpdateState(trainedNet,XTest(:,i));
end
(2).
for i=1:size(XTest,2)
[YTest(:,i),state]=predict(trainedNet,XTest(:,i));
trainedNet.State=state;
end
I wonder that what is the reseason for this phenomenon? Or, what is the difference between the ways of predict() and PredictAndUpdateState() to update networks?
Any help will be appreciated!Hi All,
I found the following two ways of predicting performs differently:
(1).
for i=1:size(XTest,2)
[trainedNet,YTest(:,i)]=PredictAndUpdateState(trainedNet,XTest(:,i));
end
(2).
for i=1:size(XTest,2)
[YTest(:,i),state]=predict(trainedNet,XTest(:,i));
trainedNet.State=state;
end
I wonder that what is the reseason for this phenomenon? Or, what is the difference between the ways of predict() and PredictAndUpdateState() to update networks?
Any help will be appreciated! Hi All,
I found the following two ways of predicting performs differently:
(1).
for i=1:size(XTest,2)
[trainedNet,YTest(:,i)]=PredictAndUpdateState(trainedNet,XTest(:,i));
end
(2).
for i=1:size(XTest,2)
[YTest(:,i),state]=predict(trainedNet,XTest(:,i));
trainedNet.State=state;
end
I wonder that what is the reseason for this phenomenon? Or, what is the difference between the ways of predict() and PredictAndUpdateState() to update networks?
Any help will be appreciated! lstm, predictandupdatestate, predict, prediction, deep learning MATLAB Answers — New Questions
How to Remove Extra Subplot When Custom Plotting with ‘particleswarm’?
Hello MATLAB Community,
I’m working on implementing a custom plot function for the particleswarm function in the Global Optimization Toolbox. However, I’m encountering an issue where an extra empty subplot is being generated along with the intended plots. I would like to know how to remove this extra subplot.
Here is my full code:
fun = @(x) 3*(1-x(1)).^2.*exp(-(x(1).^2)-(x(2)+1).^2)…
– 10*(x(1)/5 – x(1).^3 – x(2).^5).*exp(-x(1).^2-x(2).^2)…
– 1/3*exp(-(x(1)+1).^2 – x(2).^2);
xbounds = [-3, 3, -3, 3]; % [xmin xmax ymin ymax]
fconvert = @(x1, x2) fun([x1, x2]); % for fsurf, fun should be defined as fun = @(x1,x2,…,xn) but for PSO, fun = @(x)
myfig = fsurf(fconvert, xbounds,’ShowContours’,’on’, ‘FaceAlpha’, 0.7);
xlabel(‘x1’);
ylabel(‘x2’);
zlabel(‘f(x1, x2)’);
box on
plotFcnWithHandle = @(optimValues, state) myplot(optimValues, state, myfig);
rng default % For reproducibility
nvars = 2;
lb = [xbounds(1), xbounds(3)];
ub = [xbounds(2), xbounds(4)];
options = optimoptions(‘particleswarm’, …
‘SwarmSize’, 50,…
‘Display’,’iter’,…
‘DisplayInterval’, 1,…
‘FunctionTolerance’, 0.01,…
‘MaxIterations’, 500,…
‘MaxStallIterations’, 20,…
‘PlotFcn’, {‘pswplotbestf’,plotFcnWithHandle});
[x,fval] = particleswarm(fun,nvars,lb,ub,options);
function stop = myplot(optimValues, state, myfig)
stop = false;
ax = get(myfig,’Parent’);
positions = optimValues.swarm;
hold(ax, ‘on’);
delete(findall(ax, ‘Tag’, ‘particles’));
scatter3(ax, positions(:,1), positions(:,2), optimValues.swarmfvals, …
‘r’, ‘filled’, ‘MarkerEdgeColor’,’k’, ‘Tag’, ‘particles’);
% Update the figure
drawnow;
pause(1); % Pause for 1 second
end
In the code above, an extra empty subplot is generated in addition to the intended plot in the figure titled as "particleswarm". I would like to know how to prevent or remove this extra subplot. Thank you for your help!Hello MATLAB Community,
I’m working on implementing a custom plot function for the particleswarm function in the Global Optimization Toolbox. However, I’m encountering an issue where an extra empty subplot is being generated along with the intended plots. I would like to know how to remove this extra subplot.
Here is my full code:
fun = @(x) 3*(1-x(1)).^2.*exp(-(x(1).^2)-(x(2)+1).^2)…
– 10*(x(1)/5 – x(1).^3 – x(2).^5).*exp(-x(1).^2-x(2).^2)…
– 1/3*exp(-(x(1)+1).^2 – x(2).^2);
xbounds = [-3, 3, -3, 3]; % [xmin xmax ymin ymax]
fconvert = @(x1, x2) fun([x1, x2]); % for fsurf, fun should be defined as fun = @(x1,x2,…,xn) but for PSO, fun = @(x)
myfig = fsurf(fconvert, xbounds,’ShowContours’,’on’, ‘FaceAlpha’, 0.7);
xlabel(‘x1’);
ylabel(‘x2’);
zlabel(‘f(x1, x2)’);
box on
plotFcnWithHandle = @(optimValues, state) myplot(optimValues, state, myfig);
rng default % For reproducibility
nvars = 2;
lb = [xbounds(1), xbounds(3)];
ub = [xbounds(2), xbounds(4)];
options = optimoptions(‘particleswarm’, …
‘SwarmSize’, 50,…
‘Display’,’iter’,…
‘DisplayInterval’, 1,…
‘FunctionTolerance’, 0.01,…
‘MaxIterations’, 500,…
‘MaxStallIterations’, 20,…
‘PlotFcn’, {‘pswplotbestf’,plotFcnWithHandle});
[x,fval] = particleswarm(fun,nvars,lb,ub,options);
function stop = myplot(optimValues, state, myfig)
stop = false;
ax = get(myfig,’Parent’);
positions = optimValues.swarm;
hold(ax, ‘on’);
delete(findall(ax, ‘Tag’, ‘particles’));
scatter3(ax, positions(:,1), positions(:,2), optimValues.swarmfvals, …
‘r’, ‘filled’, ‘MarkerEdgeColor’,’k’, ‘Tag’, ‘particles’);
% Update the figure
drawnow;
pause(1); % Pause for 1 second
end
In the code above, an extra empty subplot is generated in addition to the intended plot in the figure titled as "particleswarm". I would like to know how to prevent or remove this extra subplot. Thank you for your help! Hello MATLAB Community,
I’m working on implementing a custom plot function for the particleswarm function in the Global Optimization Toolbox. However, I’m encountering an issue where an extra empty subplot is being generated along with the intended plots. I would like to know how to remove this extra subplot.
Here is my full code:
fun = @(x) 3*(1-x(1)).^2.*exp(-(x(1).^2)-(x(2)+1).^2)…
– 10*(x(1)/5 – x(1).^3 – x(2).^5).*exp(-x(1).^2-x(2).^2)…
– 1/3*exp(-(x(1)+1).^2 – x(2).^2);
xbounds = [-3, 3, -3, 3]; % [xmin xmax ymin ymax]
fconvert = @(x1, x2) fun([x1, x2]); % for fsurf, fun should be defined as fun = @(x1,x2,…,xn) but for PSO, fun = @(x)
myfig = fsurf(fconvert, xbounds,’ShowContours’,’on’, ‘FaceAlpha’, 0.7);
xlabel(‘x1’);
ylabel(‘x2’);
zlabel(‘f(x1, x2)’);
box on
plotFcnWithHandle = @(optimValues, state) myplot(optimValues, state, myfig);
rng default % For reproducibility
nvars = 2;
lb = [xbounds(1), xbounds(3)];
ub = [xbounds(2), xbounds(4)];
options = optimoptions(‘particleswarm’, …
‘SwarmSize’, 50,…
‘Display’,’iter’,…
‘DisplayInterval’, 1,…
‘FunctionTolerance’, 0.01,…
‘MaxIterations’, 500,…
‘MaxStallIterations’, 20,…
‘PlotFcn’, {‘pswplotbestf’,plotFcnWithHandle});
[x,fval] = particleswarm(fun,nvars,lb,ub,options);
function stop = myplot(optimValues, state, myfig)
stop = false;
ax = get(myfig,’Parent’);
positions = optimValues.swarm;
hold(ax, ‘on’);
delete(findall(ax, ‘Tag’, ‘particles’));
scatter3(ax, positions(:,1), positions(:,2), optimValues.swarmfvals, …
‘r’, ‘filled’, ‘MarkerEdgeColor’,’k’, ‘Tag’, ‘particles’);
% Update the figure
drawnow;
pause(1); % Pause for 1 second
end
In the code above, an extra empty subplot is generated in addition to the intended plot in the figure titled as "particleswarm". I would like to know how to prevent or remove this extra subplot. Thank you for your help! particle swarm optimization, global optimization toolbox MATLAB Answers — New Questions
To convert RT structure set from DICOM format to uncompressed NIfTI (.nii) format
I want to convert RT structure set from DICOM format to uncompressed NIfTI (.nii) format.I want to convert RT structure set from DICOM format to uncompressed NIfTI (.nii) format. I want to convert RT structure set from DICOM format to uncompressed NIfTI (.nii) format. rt structure set, dicom, nifti MATLAB Answers — New Questions
.NET method with “out” keyword as an input
Hello!
I’ve run into a tricky situation when trying to work with a .NET library inside MATLAB. Normally, it appears that when a .NET method has a parameter with the out keyword, MATLAB makes it a parameter that is returned instead.
However, I have run into an unusual scenario where a function requires me to input a value for a parameter with the out keyword. I cannot find a public repository for the library in question; However, I’ve included below an example of how the .NET function in question, ZernikeLSF, is called in a C# script:
After going through the MATLAB documentation on its .NET integration, I have been unable to find a way to input a value for this parameter, zernike_order — I can only seem to have it be returned. Is there a method of inputting a value here with MATLAB? If not, are there any good workarounds?Hello!
I’ve run into a tricky situation when trying to work with a .NET library inside MATLAB. Normally, it appears that when a .NET method has a parameter with the out keyword, MATLAB makes it a parameter that is returned instead.
However, I have run into an unusual scenario where a function requires me to input a value for a parameter with the out keyword. I cannot find a public repository for the library in question; However, I’ve included below an example of how the .NET function in question, ZernikeLSF, is called in a C# script:
After going through the MATLAB documentation on its .NET integration, I have been unable to find a way to input a value for this parameter, zernike_order — I can only seem to have it be returned. Is there a method of inputting a value here with MATLAB? If not, are there any good workarounds? Hello!
I’ve run into a tricky situation when trying to work with a .NET library inside MATLAB. Normally, it appears that when a .NET method has a parameter with the out keyword, MATLAB makes it a parameter that is returned instead.
However, I have run into an unusual scenario where a function requires me to input a value for a parameter with the out keyword. I cannot find a public repository for the library in question; However, I’ve included below an example of how the .NET function in question, ZernikeLSF, is called in a C# script:
After going through the MATLAB documentation on its .NET integration, I have been unable to find a way to input a value for this parameter, zernike_order — I can only seem to have it be returned. Is there a method of inputting a value here with MATLAB? If not, are there any good workarounds? .net, handles MATLAB Answers — New Questions
Representing an area on a different axis.
I have an area bounded by a data set in the (-) plane as shown below. Is it mathematically possible to represent this area (blue color) in (-) plane?
clear; clc;
data = [1.0000 0.9000 0.8000 0.7000 0.6000 0.5000 0.4000 0.3000 0.2000 0.1000 0 -0.1000 -0.2000 -0.3000 -0.4000 -0.5000 -0.6000 -0.6000 -0.6000 -0.6000 -0.6000 -0.5000 -0.4000 -0.3000 -0.2000 -0.1000 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000
-2.1351 -2.1892 -2.2432 -2.2973 -2.3243 -2.3243 -2.3243 -2.3514 -2.2703 -2.2432 -2.2432 -2.2432 -2.2703 -2.2973 -2.2162 -2.1081 -2.0000 -1.0541 0.0270 1.1081 1.3243 2.6486 4.0270 5.2703 6.5676 7.5405 8.2973 9.1081 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000];
x = data(1, :);
y = data(2, :);
figure
fill(x, y, ‘b’,’FaceAlpha’,0.5)
xlabel(‘Q_2/Q_4+1’)
ylabel(‘Q/Q_4+5’)
set(gca,’FontName’,’times’,’fontsize’,14)I have an area bounded by a data set in the (-) plane as shown below. Is it mathematically possible to represent this area (blue color) in (-) plane?
clear; clc;
data = [1.0000 0.9000 0.8000 0.7000 0.6000 0.5000 0.4000 0.3000 0.2000 0.1000 0 -0.1000 -0.2000 -0.3000 -0.4000 -0.5000 -0.6000 -0.6000 -0.6000 -0.6000 -0.6000 -0.5000 -0.4000 -0.3000 -0.2000 -0.1000 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000
-2.1351 -2.1892 -2.2432 -2.2973 -2.3243 -2.3243 -2.3243 -2.3514 -2.2703 -2.2432 -2.2432 -2.2432 -2.2703 -2.2973 -2.2162 -2.1081 -2.0000 -1.0541 0.0270 1.1081 1.3243 2.6486 4.0270 5.2703 6.5676 7.5405 8.2973 9.1081 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000];
x = data(1, :);
y = data(2, :);
figure
fill(x, y, ‘b’,’FaceAlpha’,0.5)
xlabel(‘Q_2/Q_4+1’)
ylabel(‘Q/Q_4+5’)
set(gca,’FontName’,’times’,’fontsize’,14) I have an area bounded by a data set in the (-) plane as shown below. Is it mathematically possible to represent this area (blue color) in (-) plane?
clear; clc;
data = [1.0000 0.9000 0.8000 0.7000 0.6000 0.5000 0.4000 0.3000 0.2000 0.1000 0 -0.1000 -0.2000 -0.3000 -0.4000 -0.5000 -0.6000 -0.6000 -0.6000 -0.6000 -0.6000 -0.5000 -0.4000 -0.3000 -0.2000 -0.1000 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000
-2.1351 -2.1892 -2.2432 -2.2973 -2.3243 -2.3243 -2.3243 -2.3514 -2.2703 -2.2432 -2.2432 -2.2432 -2.2703 -2.2973 -2.2162 -2.1081 -2.0000 -1.0541 0.0270 1.1081 1.3243 2.6486 4.0270 5.2703 6.5676 7.5405 8.2973 9.1081 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000 10.0000];
x = data(1, :);
y = data(2, :);
figure
fill(x, y, ‘b’,’FaceAlpha’,0.5)
xlabel(‘Q_2/Q_4+1’)
ylabel(‘Q/Q_4+5’)
set(gca,’FontName’,’times’,’fontsize’,14) logic, math, mathematics MATLAB Answers — New Questions