Tag Archives: matlab
I am finding issues in PDEPe which shows time integration failure again and again
"Warning: Failure at t=2.088125e-04. Unable to meet integration tolerances without reducing the step size
below the smallest value allowed (4.336809e-19) at time t. "
This message is being shown for running my code. I am uploading my code below.
clear all
clc
close all
m=0;
x=linspace(0,1,1001);
t=linspace(0,1,1001);
options = odeset(‘RelTol’, 1e-3, ‘AbsTol’, 1e-6,’MaxStep’, 0.1);
sol=pdepe(m,@coupledpde_BACD,@coupledic_BACD,@coupledbc_BACD,x,t,options);
b=sol(:,:,1);
figure(1)
surf(x,t,b)
xlabel(‘x’)
ylabel(‘t’)
zlabel(‘b(x,t)’)
grid on
title(‘Bacterial distribution’);
view([150 25])
colorbar
colormap jet
for j=[1 11 101]
ylim([0,1.2])
figure(2)
hold on
plot(x,b(j,:),LineWidth=2)
title("Particle Concentration Profile at t= (1, 11, 101)*td")
xlabel("Characteristic length")
ylabel(‘bacteria Concentration’)
end
function [c,f,s]= coupledpde_BACD(x,t,u, dudx)
Db=10^-12;
Dc=10^-9;
X0=10^-9;
% X0=linspace(10^-11,10^-9,100);
% Db=linspace(10^-13,10^-12,100);
c=1;
s=0;
l=[pi/2 3*pi/2 5*pi/2];
A=4.*(cos(l)-1)./(2.*l-sin(2.*l));
mob_ratio=X0/Dc;
d_ratio=Db/Dc;
f=(d_ratio).*dudx-u*(mob_ratio)./(1+exp(-l(1)^2.*t).*A(1).*sin(l(1).*x)).*(exp(-l(1)^2.*t).*A(1).*cos(l(1).*x).*l(1));
end
function u0 = coupledic_BACD(x)
u0=1;
end
function [pl,ql,pr,qr]= coupledbc_BACD(xl,ul,xr,ur,t)
pl=ul;
ql=0;
pr=0;
qr=1;
end
please help me find the issue in the code"Warning: Failure at t=2.088125e-04. Unable to meet integration tolerances without reducing the step size
below the smallest value allowed (4.336809e-19) at time t. "
This message is being shown for running my code. I am uploading my code below.
clear all
clc
close all
m=0;
x=linspace(0,1,1001);
t=linspace(0,1,1001);
options = odeset(‘RelTol’, 1e-3, ‘AbsTol’, 1e-6,’MaxStep’, 0.1);
sol=pdepe(m,@coupledpde_BACD,@coupledic_BACD,@coupledbc_BACD,x,t,options);
b=sol(:,:,1);
figure(1)
surf(x,t,b)
xlabel(‘x’)
ylabel(‘t’)
zlabel(‘b(x,t)’)
grid on
title(‘Bacterial distribution’);
view([150 25])
colorbar
colormap jet
for j=[1 11 101]
ylim([0,1.2])
figure(2)
hold on
plot(x,b(j,:),LineWidth=2)
title("Particle Concentration Profile at t= (1, 11, 101)*td")
xlabel("Characteristic length")
ylabel(‘bacteria Concentration’)
end
function [c,f,s]= coupledpde_BACD(x,t,u, dudx)
Db=10^-12;
Dc=10^-9;
X0=10^-9;
% X0=linspace(10^-11,10^-9,100);
% Db=linspace(10^-13,10^-12,100);
c=1;
s=0;
l=[pi/2 3*pi/2 5*pi/2];
A=4.*(cos(l)-1)./(2.*l-sin(2.*l));
mob_ratio=X0/Dc;
d_ratio=Db/Dc;
f=(d_ratio).*dudx-u*(mob_ratio)./(1+exp(-l(1)^2.*t).*A(1).*sin(l(1).*x)).*(exp(-l(1)^2.*t).*A(1).*cos(l(1).*x).*l(1));
end
function u0 = coupledic_BACD(x)
u0=1;
end
function [pl,ql,pr,qr]= coupledbc_BACD(xl,ul,xr,ur,t)
pl=ul;
ql=0;
pr=0;
qr=1;
end
please help me find the issue in the code "Warning: Failure at t=2.088125e-04. Unable to meet integration tolerances without reducing the step size
below the smallest value allowed (4.336809e-19) at time t. "
This message is being shown for running my code. I am uploading my code below.
clear all
clc
close all
m=0;
x=linspace(0,1,1001);
t=linspace(0,1,1001);
options = odeset(‘RelTol’, 1e-3, ‘AbsTol’, 1e-6,’MaxStep’, 0.1);
sol=pdepe(m,@coupledpde_BACD,@coupledic_BACD,@coupledbc_BACD,x,t,options);
b=sol(:,:,1);
figure(1)
surf(x,t,b)
xlabel(‘x’)
ylabel(‘t’)
zlabel(‘b(x,t)’)
grid on
title(‘Bacterial distribution’);
view([150 25])
colorbar
colormap jet
for j=[1 11 101]
ylim([0,1.2])
figure(2)
hold on
plot(x,b(j,:),LineWidth=2)
title("Particle Concentration Profile at t= (1, 11, 101)*td")
xlabel("Characteristic length")
ylabel(‘bacteria Concentration’)
end
function [c,f,s]= coupledpde_BACD(x,t,u, dudx)
Db=10^-12;
Dc=10^-9;
X0=10^-9;
% X0=linspace(10^-11,10^-9,100);
% Db=linspace(10^-13,10^-12,100);
c=1;
s=0;
l=[pi/2 3*pi/2 5*pi/2];
A=4.*(cos(l)-1)./(2.*l-sin(2.*l));
mob_ratio=X0/Dc;
d_ratio=Db/Dc;
f=(d_ratio).*dudx-u*(mob_ratio)./(1+exp(-l(1)^2.*t).*A(1).*sin(l(1).*x)).*(exp(-l(1)^2.*t).*A(1).*cos(l(1).*x).*l(1));
end
function u0 = coupledic_BACD(x)
u0=1;
end
function [pl,ql,pr,qr]= coupledbc_BACD(xl,ul,xr,ur,t)
pl=ul;
ql=0;
pr=0;
qr=1;
end
please help me find the issue in the code pdepe, time integration failure MATLAB Answers — New Questions
loop plot add text to only one specific plot year
Background:
time series for temp and chlorophyll from 2006 to current
created subplots for annual plots (four plots and text in the 5th subplot) (2006, 2007, 2008….2024)
saved title with the specific year for each plot (used num2str)
saved to correct path with the year in the filename (used num2str) filename = [‘AnnualPlots ‘, num2str(datedata), ‘.jpg’], datedata;
filenames are AnnualPlots 2006.jpg, AnnualPlots 2007.jpg, …AnnualPlots 2024.jpg
Everything checks out….
We had a sampling pause in 2020 and 2021…you know why. I would like to label this in the 2020 plot and 2021 plot.
???Is it possible to add details to an individual plot within a loop like code??? This is for outreach and I have limited coding experience.
% extract date, total chla, 3µm chla, 1 to 3 µm chla, > 3 µm chla
date = Data.DATEPST; % date sampled
sampletemp = Data.Sample_Temp; % deg C
chlaTotal = Data.TChla; % µg/L
chla3um = Data.Chla3um;% µg/L
chla3um1 = Data.Chla3um1; % 3µm>Chla percent(%)
chla3um2 = Data.Chla3um2; % 3µm<Chla percent(%)
% Get the current year
currentYear = year(datetime(‘now’));
% Iterate over each year from 2006 to the current year
for datedata = 2006:currentYear
% Create a new figure for each year
figure;
set(gcf, ‘Position’, [10,10,800,600])
subplot(5,1,1);
plot(date,sampletemp,"color","#4682B4", "LineWidth",0.5); % #4682B4 steal blue
yyaxis left
title({[num2str(datedata) ‘ Coastal Water (10 m depth)’] ‘California’});
ylabel(‘Temp (^oC)’)
xlim([datetime(datedata,1,1,0,0,0)…
datetime(datedata,12,31,0,0,0)])
datetick(‘x’,’mmm’,’keeplimits’,’keepticks’)
ylim([6 29])
where would this go and how to relate it to AnnualPlots 2020.jpg???
txt1 = ‘- – – – anthropause – – – -‘;
text(x,3,txt1,’Color’,’red’,’FontSize’,10,’Rotation’,0);
%yyaxis default was red; following code changes it back to black
ax = gca;
ax.YColor = ‘k’;
subplot(5,1,2);
…
subplot(5,1,3);
…
subplot(5,1,4);
…
subplot(5,1,5);
…
% Save each figure to a specific folder
filepath = ‘C:MeDesktopwebsite figures’;
filename = [‘AnnualPlots ‘, num2str(datedata), ‘.jpg’], datedata;
saveas(gcf, fullfile(filepath,filename));
endBackground:
time series for temp and chlorophyll from 2006 to current
created subplots for annual plots (four plots and text in the 5th subplot) (2006, 2007, 2008….2024)
saved title with the specific year for each plot (used num2str)
saved to correct path with the year in the filename (used num2str) filename = [‘AnnualPlots ‘, num2str(datedata), ‘.jpg’], datedata;
filenames are AnnualPlots 2006.jpg, AnnualPlots 2007.jpg, …AnnualPlots 2024.jpg
Everything checks out….
We had a sampling pause in 2020 and 2021…you know why. I would like to label this in the 2020 plot and 2021 plot.
???Is it possible to add details to an individual plot within a loop like code??? This is for outreach and I have limited coding experience.
% extract date, total chla, 3µm chla, 1 to 3 µm chla, > 3 µm chla
date = Data.DATEPST; % date sampled
sampletemp = Data.Sample_Temp; % deg C
chlaTotal = Data.TChla; % µg/L
chla3um = Data.Chla3um;% µg/L
chla3um1 = Data.Chla3um1; % 3µm>Chla percent(%)
chla3um2 = Data.Chla3um2; % 3µm<Chla percent(%)
% Get the current year
currentYear = year(datetime(‘now’));
% Iterate over each year from 2006 to the current year
for datedata = 2006:currentYear
% Create a new figure for each year
figure;
set(gcf, ‘Position’, [10,10,800,600])
subplot(5,1,1);
plot(date,sampletemp,"color","#4682B4", "LineWidth",0.5); % #4682B4 steal blue
yyaxis left
title({[num2str(datedata) ‘ Coastal Water (10 m depth)’] ‘California’});
ylabel(‘Temp (^oC)’)
xlim([datetime(datedata,1,1,0,0,0)…
datetime(datedata,12,31,0,0,0)])
datetick(‘x’,’mmm’,’keeplimits’,’keepticks’)
ylim([6 29])
where would this go and how to relate it to AnnualPlots 2020.jpg???
txt1 = ‘- – – – anthropause – – – -‘;
text(x,3,txt1,’Color’,’red’,’FontSize’,10,’Rotation’,0);
%yyaxis default was red; following code changes it back to black
ax = gca;
ax.YColor = ‘k’;
subplot(5,1,2);
…
subplot(5,1,3);
…
subplot(5,1,4);
…
subplot(5,1,5);
…
% Save each figure to a specific folder
filepath = ‘C:MeDesktopwebsite figures’;
filename = [‘AnnualPlots ‘, num2str(datedata), ‘.jpg’], datedata;
saveas(gcf, fullfile(filepath,filename));
end Background:
time series for temp and chlorophyll from 2006 to current
created subplots for annual plots (four plots and text in the 5th subplot) (2006, 2007, 2008….2024)
saved title with the specific year for each plot (used num2str)
saved to correct path with the year in the filename (used num2str) filename = [‘AnnualPlots ‘, num2str(datedata), ‘.jpg’], datedata;
filenames are AnnualPlots 2006.jpg, AnnualPlots 2007.jpg, …AnnualPlots 2024.jpg
Everything checks out….
We had a sampling pause in 2020 and 2021…you know why. I would like to label this in the 2020 plot and 2021 plot.
???Is it possible to add details to an individual plot within a loop like code??? This is for outreach and I have limited coding experience.
% extract date, total chla, 3µm chla, 1 to 3 µm chla, > 3 µm chla
date = Data.DATEPST; % date sampled
sampletemp = Data.Sample_Temp; % deg C
chlaTotal = Data.TChla; % µg/L
chla3um = Data.Chla3um;% µg/L
chla3um1 = Data.Chla3um1; % 3µm>Chla percent(%)
chla3um2 = Data.Chla3um2; % 3µm<Chla percent(%)
% Get the current year
currentYear = year(datetime(‘now’));
% Iterate over each year from 2006 to the current year
for datedata = 2006:currentYear
% Create a new figure for each year
figure;
set(gcf, ‘Position’, [10,10,800,600])
subplot(5,1,1);
plot(date,sampletemp,"color","#4682B4", "LineWidth",0.5); % #4682B4 steal blue
yyaxis left
title({[num2str(datedata) ‘ Coastal Water (10 m depth)’] ‘California’});
ylabel(‘Temp (^oC)’)
xlim([datetime(datedata,1,1,0,0,0)…
datetime(datedata,12,31,0,0,0)])
datetick(‘x’,’mmm’,’keeplimits’,’keepticks’)
ylim([6 29])
where would this go and how to relate it to AnnualPlots 2020.jpg???
txt1 = ‘- – – – anthropause – – – -‘;
text(x,3,txt1,’Color’,’red’,’FontSize’,10,’Rotation’,0);
%yyaxis default was red; following code changes it back to black
ax = gca;
ax.YColor = ‘k’;
subplot(5,1,2);
…
subplot(5,1,3);
…
subplot(5,1,4);
…
subplot(5,1,5);
…
% Save each figure to a specific folder
filepath = ‘C:MeDesktopwebsite figures’;
filename = [‘AnnualPlots ‘, num2str(datedata), ‘.jpg’], datedata;
saveas(gcf, fullfile(filepath,filename));
end time series, for loop, text MATLAB Answers — New Questions
Defining variable as a function of other variable
I am trying to define t as a function of k so that when I substitute compute_obj with define_t and then differentiate the objective_with_t function wrt k, Matlab should differentiate variable t for being a function of k. I tried numerous ways to define t as a function of k. Following code shows one of the ways in which I tried to do it –
% Define symbolic variables
syms k t real
% Define the relationship between k and t
t_k = @(k) t; % t is a function of k
% Define the expressions
compute_obj = -(sqrt(1 – k) * (t_k(k)^6 * (2 * m * (3 * m + 2) + 4) – t_k(k)^5 * (m * (m * (5 * m + 6) + 11) + 12) + m^6 + 2 * t_k(k)^7 – t_k(k)^8 – t_k(k)^4 * (m * (3 * m * (m * (3 * m + 2) – 3) – 16) – 9) – 2 * m^3 * t_k(k)^2 * (3 * m^3 + 2 * m + 3) + m^2 * t_k(k)^3 * (m * (3 * m * (5 * m + 4) + 1) – 4)) + sqrt(k) * (t_k(k)^4 * (m * (9 * m * (m * (m + 4) + 5) + 28) + 9) – m^4 * (3 * m – 2) – t_k(k)^6 * (6 * m * (m + 2) + 10) + t_k(k)^5 * (4 * m^3 + 12 * m + 8) + t_k(k)^8 + m * t_k(k)^2 * (m * (m * (4 * m^3 + 3 * m + 9) + 6) – 8) + 2 * m^2 * t_k(k) * (3 * m – 2) – 2 * m * t_k(k)^3 * (m * (m * (6 * m * (m + 2) + 7) + 6) – 2))) / (18 * t_k(k)^3 * (2 * t_k(k) – (m – t_k(k))^2));
define_t = (sqrt(k) * ((m / t + 2) / 3) – sqrt(1 – k) * ((1 / 3) * (2 + (m / t) + ((2 * m + t) / ((m – t)^2 – 2 * t))))) / (sqrt(k) * (2 * m^3 – 3 * (1 + m)^2 * t + t^3) / (3 * ((m – t)^2 – 2 * t)) – sqrt(1 – k) * ((2 * m + t) / 3));
% Main loop to solve for each m
m_values = linspace(0, 1, 100);
k_solutions = zeros(size(m_values));
t_solutions = zeros(size(m_values));
for i = 1:length(m_values)
m = m_values(i);
% Define the objective function with current m and symbolic t
objective_with_t = compute_obj;
% Differentiate the objective function with respect to k
d_obj_d_k = diff(objective_with_t, k);
% Convert the symbolic derivative to a MATLAB function
d_obj_d_k_fn = matlabFunction(d_obj_d_k, ‘Vars’, [k, t]);
% Define a function for numerical root finding to find optimal k
opt_k_fn = @(k_val) d_obj_d_k_fn(k_val, t_k(k_val));
% Use fminbnd to find the optimal k in the range [0.5, 1]
options = optimset(‘Display’, ‘off’);
k_opt = fminbnd(@(k) abs(opt_k_fn(k)), 0.5, 1, options);
% Define a function for numerical root finding to find t_opt
func = matlabFunction(t_k(k) – define_t, ‘Vars’, t);
% Use numerical root finding to find the fixed point of t
try
t_opt = fzero(func, 0.7); % Assuming a starting guess for t
catch
t_opt = NaN;
end
% Store solutions
k_solutions(i) = k_opt;
t_solutions(i) = t_opt;
end
% Display solutions
disp(table(m_values’, k_solutions’, t_solutions’, ‘VariableNames’, {‘m’, ‘k_opt’, ‘t_opt’}));
% Plot results
figure;
plot(m_values, k_solutions, ‘b-‘, ‘LineWidth’, 1.5);
hold on;
plot(m_values, t_solutions, ‘r–‘, ‘LineWidth’, 1.5);
xlabel(‘m’);
ylabel(‘Value’);
legend(‘Optimal k’, ‘Optimal t’);
title(‘Stackelberg Equilibrium Solutions’);
hold off;
I keep getting error. Please someone suggest a way to define t as function of kI am trying to define t as a function of k so that when I substitute compute_obj with define_t and then differentiate the objective_with_t function wrt k, Matlab should differentiate variable t for being a function of k. I tried numerous ways to define t as a function of k. Following code shows one of the ways in which I tried to do it –
% Define symbolic variables
syms k t real
% Define the relationship between k and t
t_k = @(k) t; % t is a function of k
% Define the expressions
compute_obj = -(sqrt(1 – k) * (t_k(k)^6 * (2 * m * (3 * m + 2) + 4) – t_k(k)^5 * (m * (m * (5 * m + 6) + 11) + 12) + m^6 + 2 * t_k(k)^7 – t_k(k)^8 – t_k(k)^4 * (m * (3 * m * (m * (3 * m + 2) – 3) – 16) – 9) – 2 * m^3 * t_k(k)^2 * (3 * m^3 + 2 * m + 3) + m^2 * t_k(k)^3 * (m * (3 * m * (5 * m + 4) + 1) – 4)) + sqrt(k) * (t_k(k)^4 * (m * (9 * m * (m * (m + 4) + 5) + 28) + 9) – m^4 * (3 * m – 2) – t_k(k)^6 * (6 * m * (m + 2) + 10) + t_k(k)^5 * (4 * m^3 + 12 * m + 8) + t_k(k)^8 + m * t_k(k)^2 * (m * (m * (4 * m^3 + 3 * m + 9) + 6) – 8) + 2 * m^2 * t_k(k) * (3 * m – 2) – 2 * m * t_k(k)^3 * (m * (m * (6 * m * (m + 2) + 7) + 6) – 2))) / (18 * t_k(k)^3 * (2 * t_k(k) – (m – t_k(k))^2));
define_t = (sqrt(k) * ((m / t + 2) / 3) – sqrt(1 – k) * ((1 / 3) * (2 + (m / t) + ((2 * m + t) / ((m – t)^2 – 2 * t))))) / (sqrt(k) * (2 * m^3 – 3 * (1 + m)^2 * t + t^3) / (3 * ((m – t)^2 – 2 * t)) – sqrt(1 – k) * ((2 * m + t) / 3));
% Main loop to solve for each m
m_values = linspace(0, 1, 100);
k_solutions = zeros(size(m_values));
t_solutions = zeros(size(m_values));
for i = 1:length(m_values)
m = m_values(i);
% Define the objective function with current m and symbolic t
objective_with_t = compute_obj;
% Differentiate the objective function with respect to k
d_obj_d_k = diff(objective_with_t, k);
% Convert the symbolic derivative to a MATLAB function
d_obj_d_k_fn = matlabFunction(d_obj_d_k, ‘Vars’, [k, t]);
% Define a function for numerical root finding to find optimal k
opt_k_fn = @(k_val) d_obj_d_k_fn(k_val, t_k(k_val));
% Use fminbnd to find the optimal k in the range [0.5, 1]
options = optimset(‘Display’, ‘off’);
k_opt = fminbnd(@(k) abs(opt_k_fn(k)), 0.5, 1, options);
% Define a function for numerical root finding to find t_opt
func = matlabFunction(t_k(k) – define_t, ‘Vars’, t);
% Use numerical root finding to find the fixed point of t
try
t_opt = fzero(func, 0.7); % Assuming a starting guess for t
catch
t_opt = NaN;
end
% Store solutions
k_solutions(i) = k_opt;
t_solutions(i) = t_opt;
end
% Display solutions
disp(table(m_values’, k_solutions’, t_solutions’, ‘VariableNames’, {‘m’, ‘k_opt’, ‘t_opt’}));
% Plot results
figure;
plot(m_values, k_solutions, ‘b-‘, ‘LineWidth’, 1.5);
hold on;
plot(m_values, t_solutions, ‘r–‘, ‘LineWidth’, 1.5);
xlabel(‘m’);
ylabel(‘Value’);
legend(‘Optimal k’, ‘Optimal t’);
title(‘Stackelberg Equilibrium Solutions’);
hold off;
I keep getting error. Please someone suggest a way to define t as function of k I am trying to define t as a function of k so that when I substitute compute_obj with define_t and then differentiate the objective_with_t function wrt k, Matlab should differentiate variable t for being a function of k. I tried numerous ways to define t as a function of k. Following code shows one of the ways in which I tried to do it –
% Define symbolic variables
syms k t real
% Define the relationship between k and t
t_k = @(k) t; % t is a function of k
% Define the expressions
compute_obj = -(sqrt(1 – k) * (t_k(k)^6 * (2 * m * (3 * m + 2) + 4) – t_k(k)^5 * (m * (m * (5 * m + 6) + 11) + 12) + m^6 + 2 * t_k(k)^7 – t_k(k)^8 – t_k(k)^4 * (m * (3 * m * (m * (3 * m + 2) – 3) – 16) – 9) – 2 * m^3 * t_k(k)^2 * (3 * m^3 + 2 * m + 3) + m^2 * t_k(k)^3 * (m * (3 * m * (5 * m + 4) + 1) – 4)) + sqrt(k) * (t_k(k)^4 * (m * (9 * m * (m * (m + 4) + 5) + 28) + 9) – m^4 * (3 * m – 2) – t_k(k)^6 * (6 * m * (m + 2) + 10) + t_k(k)^5 * (4 * m^3 + 12 * m + 8) + t_k(k)^8 + m * t_k(k)^2 * (m * (m * (4 * m^3 + 3 * m + 9) + 6) – 8) + 2 * m^2 * t_k(k) * (3 * m – 2) – 2 * m * t_k(k)^3 * (m * (m * (6 * m * (m + 2) + 7) + 6) – 2))) / (18 * t_k(k)^3 * (2 * t_k(k) – (m – t_k(k))^2));
define_t = (sqrt(k) * ((m / t + 2) / 3) – sqrt(1 – k) * ((1 / 3) * (2 + (m / t) + ((2 * m + t) / ((m – t)^2 – 2 * t))))) / (sqrt(k) * (2 * m^3 – 3 * (1 + m)^2 * t + t^3) / (3 * ((m – t)^2 – 2 * t)) – sqrt(1 – k) * ((2 * m + t) / 3));
% Main loop to solve for each m
m_values = linspace(0, 1, 100);
k_solutions = zeros(size(m_values));
t_solutions = zeros(size(m_values));
for i = 1:length(m_values)
m = m_values(i);
% Define the objective function with current m and symbolic t
objective_with_t = compute_obj;
% Differentiate the objective function with respect to k
d_obj_d_k = diff(objective_with_t, k);
% Convert the symbolic derivative to a MATLAB function
d_obj_d_k_fn = matlabFunction(d_obj_d_k, ‘Vars’, [k, t]);
% Define a function for numerical root finding to find optimal k
opt_k_fn = @(k_val) d_obj_d_k_fn(k_val, t_k(k_val));
% Use fminbnd to find the optimal k in the range [0.5, 1]
options = optimset(‘Display’, ‘off’);
k_opt = fminbnd(@(k) abs(opt_k_fn(k)), 0.5, 1, options);
% Define a function for numerical root finding to find t_opt
func = matlabFunction(t_k(k) – define_t, ‘Vars’, t);
% Use numerical root finding to find the fixed point of t
try
t_opt = fzero(func, 0.7); % Assuming a starting guess for t
catch
t_opt = NaN;
end
% Store solutions
k_solutions(i) = k_opt;
t_solutions(i) = t_opt;
end
% Display solutions
disp(table(m_values’, k_solutions’, t_solutions’, ‘VariableNames’, {‘m’, ‘k_opt’, ‘t_opt’}));
% Plot results
figure;
plot(m_values, k_solutions, ‘b-‘, ‘LineWidth’, 1.5);
hold on;
plot(m_values, t_solutions, ‘r–‘, ‘LineWidth’, 1.5);
xlabel(‘m’);
ylabel(‘Value’);
legend(‘Optimal k’, ‘Optimal t’);
title(‘Stackelberg Equilibrium Solutions’);
hold off;
I keep getting error. Please someone suggest a way to define t as function of k function, optimization, fmincon MATLAB Answers — New Questions
MATLAB R2024a Silent Installation Issue – Unable to Load Product Files
I am facing a problem while attempting to install MATLAB R2024a on my Linux server (Ubuntu 22.04.4 LTS) using the silent installation method. Despite following the provided instructions and specifying the necessary parameters in the installer_input.txt file, the installation process fails with an error indicating that the installer is unable to load the product files.
Setup Details:
– Server Operating System: Ubuntu 22.04.4 LTS
– MATLAB Version: R2024a
– Installation Method: Silent installation using installer_input.txt file
– Path to the installer file: ~/matlab_R2024a_Linux
The error message I receive during the installation process is as follows:
“`
(May 23, 2024 23:54:26) Unable to load product files. Product files must be in the same folder as the input file. For help getting the product files, see the installation documentation on <a HREF="https://www.mathworks.com/pi_noprode_mpi_R2024a_glnxa64">MATLAB Answer</a>.
“`
I have confirmed that the MATLAB product files (contents of the "archives" directory) are located in the same directory as the installer_input.txt file. I have also verified that the installer_input.txt file does not contain any explicit line specifying the product files folder, as the installer assumes the product files are in the same directory by default.
The installation command I am using is:
“`
./install -mode silent -inputFile installer_input.txt -logFile installation_log.txt
“`
I have reviewed the installation_log.txt file, but it does not provide any additional information beyond the error message mentioned above.
To assist you in investigating this issue further, please find the following information:
– Path to the directory containing the installer_input.txt file: ~/matlab_R2024a_Linux
– List of files and directories present in the same directory as the installer_input.txt file:
“`
drwxrwxr-x 8 yugao yugao 4096 May 24 00:15 ./
drwxr-x— 33 yugao yugao 12288 May 24 00:53 ../
drwxrwxr-x 4 yugao yugao 4096 May 24 00:15 archives/
drwxrwxr-x 4 yugao yugao 4096 May 24 00:15 bin/
drwxrwxr-x 3 yugao yugao 4096 May 24 00:15 cefclient/
-r-xr-xr-x 1 yugao yugao 11147 Nov 19 2023 install*
-rw-r–r– 1 yugao yugao 9313 May 24 00:17 installer_input.txt
-r–r–r– 1 yugao yugao 83813 Jan 23 01:57 license_agreement.txt
-r–r–r– 1 yugao yugao 777345 Apr 21 11:07 mathworks_installation_help_de.pdf
-r–r–r– 1 yugao yugao 765184 Apr 20 11:01 mathworks_installation_help_es.pdf
-r–r–r– 1 yugao yugao 779814 Apr 21 10:52 mathworks_installation_help_fr.pdf
-r–r–r– 1 yugao yugao 772296 Apr 21 10:35 mathworks_installation_help_it.pdf
-r–r–r– 1 yugao yugao 652022 Apr 20 10:53 mathworks_installation_help_ja_JP.pdf
-r–r–r– 1 yugao yugao 769398 Apr 20 10:53 mathworks_installation_help_ko_KR.pdf
-r–r–r– 1 yugao yugao 760789 Apr 20 10:54 mathworks_installation_help.pdf
-r–r–r– 1 yugao yugao 874129 Apr 20 10:53 mathworks_installation_help_zh_CN.pdf
-r–r–r– 1 yugao yugao 9021 Nov 19 2023 readme.txt
drwxrwxr-x 12 yugao yugao 4096 May 24 00:15 resources/
drwxrwxr-x 4 yugao yugao 4096 May 24 00:15 sys/
drwxrwxr-x 3 yugao yugao 4096 May 24 00:15 ui/
-r–r–r– 1 yugao yugao 310 May 2 12:28 VersionInfo.xml
“`
I would greatly appreciate your guidance in resolving this silent installation issue and successfully installing MATLAB R2024a on my Ubuntu server. If you require any additional information or have specific troubleshooting steps you would like me to follow, please let me know.
Thank you for your attention to this matter and your assistance.I am facing a problem while attempting to install MATLAB R2024a on my Linux server (Ubuntu 22.04.4 LTS) using the silent installation method. Despite following the provided instructions and specifying the necessary parameters in the installer_input.txt file, the installation process fails with an error indicating that the installer is unable to load the product files.
Setup Details:
– Server Operating System: Ubuntu 22.04.4 LTS
– MATLAB Version: R2024a
– Installation Method: Silent installation using installer_input.txt file
– Path to the installer file: ~/matlab_R2024a_Linux
The error message I receive during the installation process is as follows:
“`
(May 23, 2024 23:54:26) Unable to load product files. Product files must be in the same folder as the input file. For help getting the product files, see the installation documentation on <a HREF="https://www.mathworks.com/pi_noprode_mpi_R2024a_glnxa64">MATLAB Answer</a>.
“`
I have confirmed that the MATLAB product files (contents of the "archives" directory) are located in the same directory as the installer_input.txt file. I have also verified that the installer_input.txt file does not contain any explicit line specifying the product files folder, as the installer assumes the product files are in the same directory by default.
The installation command I am using is:
“`
./install -mode silent -inputFile installer_input.txt -logFile installation_log.txt
“`
I have reviewed the installation_log.txt file, but it does not provide any additional information beyond the error message mentioned above.
To assist you in investigating this issue further, please find the following information:
– Path to the directory containing the installer_input.txt file: ~/matlab_R2024a_Linux
– List of files and directories present in the same directory as the installer_input.txt file:
“`
drwxrwxr-x 8 yugao yugao 4096 May 24 00:15 ./
drwxr-x— 33 yugao yugao 12288 May 24 00:53 ../
drwxrwxr-x 4 yugao yugao 4096 May 24 00:15 archives/
drwxrwxr-x 4 yugao yugao 4096 May 24 00:15 bin/
drwxrwxr-x 3 yugao yugao 4096 May 24 00:15 cefclient/
-r-xr-xr-x 1 yugao yugao 11147 Nov 19 2023 install*
-rw-r–r– 1 yugao yugao 9313 May 24 00:17 installer_input.txt
-r–r–r– 1 yugao yugao 83813 Jan 23 01:57 license_agreement.txt
-r–r–r– 1 yugao yugao 777345 Apr 21 11:07 mathworks_installation_help_de.pdf
-r–r–r– 1 yugao yugao 765184 Apr 20 11:01 mathworks_installation_help_es.pdf
-r–r–r– 1 yugao yugao 779814 Apr 21 10:52 mathworks_installation_help_fr.pdf
-r–r–r– 1 yugao yugao 772296 Apr 21 10:35 mathworks_installation_help_it.pdf
-r–r–r– 1 yugao yugao 652022 Apr 20 10:53 mathworks_installation_help_ja_JP.pdf
-r–r–r– 1 yugao yugao 769398 Apr 20 10:53 mathworks_installation_help_ko_KR.pdf
-r–r–r– 1 yugao yugao 760789 Apr 20 10:54 mathworks_installation_help.pdf
-r–r–r– 1 yugao yugao 874129 Apr 20 10:53 mathworks_installation_help_zh_CN.pdf
-r–r–r– 1 yugao yugao 9021 Nov 19 2023 readme.txt
drwxrwxr-x 12 yugao yugao 4096 May 24 00:15 resources/
drwxrwxr-x 4 yugao yugao 4096 May 24 00:15 sys/
drwxrwxr-x 3 yugao yugao 4096 May 24 00:15 ui/
-r–r–r– 1 yugao yugao 310 May 2 12:28 VersionInfo.xml
“`
I would greatly appreciate your guidance in resolving this silent installation issue and successfully installing MATLAB R2024a on my Ubuntu server. If you require any additional information or have specific troubleshooting steps you would like me to follow, please let me know.
Thank you for your attention to this matter and your assistance. I am facing a problem while attempting to install MATLAB R2024a on my Linux server (Ubuntu 22.04.4 LTS) using the silent installation method. Despite following the provided instructions and specifying the necessary parameters in the installer_input.txt file, the installation process fails with an error indicating that the installer is unable to load the product files.
Setup Details:
– Server Operating System: Ubuntu 22.04.4 LTS
– MATLAB Version: R2024a
– Installation Method: Silent installation using installer_input.txt file
– Path to the installer file: ~/matlab_R2024a_Linux
The error message I receive during the installation process is as follows:
“`
(May 23, 2024 23:54:26) Unable to load product files. Product files must be in the same folder as the input file. For help getting the product files, see the installation documentation on <a HREF="https://www.mathworks.com/pi_noprode_mpi_R2024a_glnxa64">MATLAB Answer</a>.
“`
I have confirmed that the MATLAB product files (contents of the "archives" directory) are located in the same directory as the installer_input.txt file. I have also verified that the installer_input.txt file does not contain any explicit line specifying the product files folder, as the installer assumes the product files are in the same directory by default.
The installation command I am using is:
“`
./install -mode silent -inputFile installer_input.txt -logFile installation_log.txt
“`
I have reviewed the installation_log.txt file, but it does not provide any additional information beyond the error message mentioned above.
To assist you in investigating this issue further, please find the following information:
– Path to the directory containing the installer_input.txt file: ~/matlab_R2024a_Linux
– List of files and directories present in the same directory as the installer_input.txt file:
“`
drwxrwxr-x 8 yugao yugao 4096 May 24 00:15 ./
drwxr-x— 33 yugao yugao 12288 May 24 00:53 ../
drwxrwxr-x 4 yugao yugao 4096 May 24 00:15 archives/
drwxrwxr-x 4 yugao yugao 4096 May 24 00:15 bin/
drwxrwxr-x 3 yugao yugao 4096 May 24 00:15 cefclient/
-r-xr-xr-x 1 yugao yugao 11147 Nov 19 2023 install*
-rw-r–r– 1 yugao yugao 9313 May 24 00:17 installer_input.txt
-r–r–r– 1 yugao yugao 83813 Jan 23 01:57 license_agreement.txt
-r–r–r– 1 yugao yugao 777345 Apr 21 11:07 mathworks_installation_help_de.pdf
-r–r–r– 1 yugao yugao 765184 Apr 20 11:01 mathworks_installation_help_es.pdf
-r–r–r– 1 yugao yugao 779814 Apr 21 10:52 mathworks_installation_help_fr.pdf
-r–r–r– 1 yugao yugao 772296 Apr 21 10:35 mathworks_installation_help_it.pdf
-r–r–r– 1 yugao yugao 652022 Apr 20 10:53 mathworks_installation_help_ja_JP.pdf
-r–r–r– 1 yugao yugao 769398 Apr 20 10:53 mathworks_installation_help_ko_KR.pdf
-r–r–r– 1 yugao yugao 760789 Apr 20 10:54 mathworks_installation_help.pdf
-r–r–r– 1 yugao yugao 874129 Apr 20 10:53 mathworks_installation_help_zh_CN.pdf
-r–r–r– 1 yugao yugao 9021 Nov 19 2023 readme.txt
drwxrwxr-x 12 yugao yugao 4096 May 24 00:15 resources/
drwxrwxr-x 4 yugao yugao 4096 May 24 00:15 sys/
drwxrwxr-x 3 yugao yugao 4096 May 24 00:15 ui/
-r–r–r– 1 yugao yugao 310 May 2 12:28 VersionInfo.xml
“`
I would greatly appreciate your guidance in resolving this silent installation issue and successfully installing MATLAB R2024a on my Ubuntu server. If you require any additional information or have specific troubleshooting steps you would like me to follow, please let me know.
Thank you for your attention to this matter and your assistance. installation MATLAB Answers — New Questions
Error using loadlibrary Building okFrontPanel_thunk_pcwin64 failed. Compiler output is: cl -I”D:QuanProgram FilesMATLABR2023bexterninclude” /Zc:__cplusplus /Zp8 /W3 /
Error using loadlibrary
Building okFrontPanel_thunk_pcwin64 failed. Compiler output is:
cl -I"D:QuanProgram FilesMATLABR2023bexterninclude" /Zc:__cplusplus /Zp8 /W3 /nologo -I"C:UsersQuanDesktop256X256matlab"
-I"C:UsersQuanDesktop256X256matlabOpal Kelly" "okFrontPanel_thunk_pcwin64.c" -LD -Fe"okFrontPanel_thunk_pcwin64.dll"
okFrontPanel_thunk_pcwin64.c
LINK : fatal error LNK1104: cannot open file ‘okFrontPanel.lib’Error using loadlibrary
Building okFrontPanel_thunk_pcwin64 failed. Compiler output is:
cl -I"D:QuanProgram FilesMATLABR2023bexterninclude" /Zc:__cplusplus /Zp8 /W3 /nologo -I"C:UsersQuanDesktop256X256matlab"
-I"C:UsersQuanDesktop256X256matlabOpal Kelly" "okFrontPanel_thunk_pcwin64.c" -LD -Fe"okFrontPanel_thunk_pcwin64.dll"
okFrontPanel_thunk_pcwin64.c
LINK : fatal error LNK1104: cannot open file ‘okFrontPanel.lib’ Error using loadlibrary
Building okFrontPanel_thunk_pcwin64 failed. Compiler output is:
cl -I"D:QuanProgram FilesMATLABR2023bexterninclude" /Zc:__cplusplus /Zp8 /W3 /nologo -I"C:UsersQuanDesktop256X256matlab"
-I"C:UsersQuanDesktop256X256matlabOpal Kelly" "okFrontPanel_thunk_pcwin64.c" -LD -Fe"okFrontPanel_thunk_pcwin64.dll"
okFrontPanel_thunk_pcwin64.c
LINK : fatal error LNK1104: cannot open file ‘okFrontPanel.lib’ link : fatal error lnk1104: cannot open file ‘okfr MATLAB Answers — New Questions
I would like to quantize a Sinewave correctly, and identify where the issues is with my code
Hi,
With the code below, I am trying to Quantize the Sinewave by varying the quantity of bits from 16-bits down via Bit Shifting, and then play a sound.
The waveform is normalised, however I am not replicating the waveform correctly and I just cannot seem to find where my error is.
I have attached some .jpg files at nBits = 1, 8 and 15.
Any help or guidance would be very appreciated.
% Sampling Frequency
fs = 8000;
% Sample Period
Ps = 1/fs;
% Sample Time from zero to two seconds in 125us steps (Ps)
t = 0:Ps:2;
% Waveform Frequency
waveFreq = 2;
% Sinewave signal
waveSignal = sin(2*pi*waveFreq*t);
waveInt = int16(waveSignal*2^15);
% Quantize waveform via truncation. (Reduce the least significant bit – LSB)
nBits = 1;
quantWave = bitshift(waveInt,nBits);
% Cast waveform back into a double data type
quantWaveDub = double(quantWave)/2^(16-nBits);
% Normalise the waveform due to bit change
quantWaveDub = quantWaveDub/max(abs(quantWaveDub));
% Plot Sinewave signal
figure(1);
plot(t,waveSignal);
ylim([-1.5 1.5]);
sound(waveSignal,fs);
pause(1);
% Plot Quantized signal
figure(2);
plot(t,quantWaveDub);
ylim([-1.5 1.5]);
sound(quantWaveDub,fs);Hi,
With the code below, I am trying to Quantize the Sinewave by varying the quantity of bits from 16-bits down via Bit Shifting, and then play a sound.
The waveform is normalised, however I am not replicating the waveform correctly and I just cannot seem to find where my error is.
I have attached some .jpg files at nBits = 1, 8 and 15.
Any help or guidance would be very appreciated.
% Sampling Frequency
fs = 8000;
% Sample Period
Ps = 1/fs;
% Sample Time from zero to two seconds in 125us steps (Ps)
t = 0:Ps:2;
% Waveform Frequency
waveFreq = 2;
% Sinewave signal
waveSignal = sin(2*pi*waveFreq*t);
waveInt = int16(waveSignal*2^15);
% Quantize waveform via truncation. (Reduce the least significant bit – LSB)
nBits = 1;
quantWave = bitshift(waveInt,nBits);
% Cast waveform back into a double data type
quantWaveDub = double(quantWave)/2^(16-nBits);
% Normalise the waveform due to bit change
quantWaveDub = quantWaveDub/max(abs(quantWaveDub));
% Plot Sinewave signal
figure(1);
plot(t,waveSignal);
ylim([-1.5 1.5]);
sound(waveSignal,fs);
pause(1);
% Plot Quantized signal
figure(2);
plot(t,quantWaveDub);
ylim([-1.5 1.5]);
sound(quantWaveDub,fs); Hi,
With the code below, I am trying to Quantize the Sinewave by varying the quantity of bits from 16-bits down via Bit Shifting, and then play a sound.
The waveform is normalised, however I am not replicating the waveform correctly and I just cannot seem to find where my error is.
I have attached some .jpg files at nBits = 1, 8 and 15.
Any help or guidance would be very appreciated.
% Sampling Frequency
fs = 8000;
% Sample Period
Ps = 1/fs;
% Sample Time from zero to two seconds in 125us steps (Ps)
t = 0:Ps:2;
% Waveform Frequency
waveFreq = 2;
% Sinewave signal
waveSignal = sin(2*pi*waveFreq*t);
waveInt = int16(waveSignal*2^15);
% Quantize waveform via truncation. (Reduce the least significant bit – LSB)
nBits = 1;
quantWave = bitshift(waveInt,nBits);
% Cast waveform back into a double data type
quantWaveDub = double(quantWave)/2^(16-nBits);
% Normalise the waveform due to bit change
quantWaveDub = quantWaveDub/max(abs(quantWaveDub));
% Plot Sinewave signal
figure(1);
plot(t,waveSignal);
ylim([-1.5 1.5]);
sound(waveSignal,fs);
pause(1);
% Plot Quantized signal
figure(2);
plot(t,quantWaveDub);
ylim([-1.5 1.5]);
sound(quantWaveDub,fs); bitshift, quantization, waveform MATLAB Answers — New Questions
Simulink – How to create a conditional “if” block
Dear experts,
I have a simulink model, in this model there are two equations.
The 1st eq applies when the speed increases from 50 to 70 rpm
The 2nd eq is applied when the speed decreases from 70 to 50 rpm
So when the speed goes from 50 to 70, I use the 1st eq. Until the speed reaches >=70.
Then I start using the 2nd eq. Until the speed reaches <=50.
and so on.
How can I create blocks for this purpose in simulink.
Thank you.Dear experts,
I have a simulink model, in this model there are two equations.
The 1st eq applies when the speed increases from 50 to 70 rpm
The 2nd eq is applied when the speed decreases from 70 to 50 rpm
So when the speed goes from 50 to 70, I use the 1st eq. Until the speed reaches >=70.
Then I start using the 2nd eq. Until the speed reaches <=50.
and so on.
How can I create blocks for this purpose in simulink.
Thank you. Dear experts,
I have a simulink model, in this model there are two equations.
The 1st eq applies when the speed increases from 50 to 70 rpm
The 2nd eq is applied when the speed decreases from 70 to 50 rpm
So when the speed goes from 50 to 70, I use the 1st eq. Until the speed reaches >=70.
Then I start using the 2nd eq. Until the speed reaches <=50.
and so on.
How can I create blocks for this purpose in simulink.
Thank you. conditional block in simulink MATLAB Answers — New Questions
A (simple) way to use ismember between datetime arrays with different formats?
Is there a (simple) way to use ismember between datetime arrays with different formats?
% Input
A = datetime(…
[’19-Jun-2023′,
’20-Jun-2023′,
’21-Jun-2023′,
’22-Jun-2023′,
’23-Jun-2023′,
’24-Jun-2023′,
’25-Jun-2023′]);
tmp = [{’23-Jun-2023 19:00:00′}
{’24-Jun-2023 16:00:00′}
{’24-Jun-2023 11:00:00′}
{’19-Jun-2023 16:00:00′}
{’20-Jun-2023 10:00:00′}
{’21-Jun-2023 10:00:00′}
{’22-Jun-2023 09:00:00′}
{’23-Jun-2023 14:00:00′}
{’19-Jun-2023 17:00:00′}
{’20-Jun-2023 11:00:00′}
{’21-Jun-2023 17:00:00′}
{’22-Jun-2023 15:00:00′}
{’23-Jun-2023 06:00:00′}
{’24-Jun-2023 11:00:00′}
{’25-Jun-2023 19:00:00′}
{’20-Jun-2023 11:00:00′}
{’21-Jun-2023 09:00:00′}
{’23-Jun-2023 12:00:00′}
{’25-Jun-2023 17:00:00′}
{’23-Jun-2023 12:00:00′}
{’22-Jun-2023 07:00:00′}];
B = datetime(tmp, ‘InputFormat’, ‘dd-MMM-yyyy HH:mm:ss’);
ismember(A,B)Is there a (simple) way to use ismember between datetime arrays with different formats?
% Input
A = datetime(…
[’19-Jun-2023′,
’20-Jun-2023′,
’21-Jun-2023′,
’22-Jun-2023′,
’23-Jun-2023′,
’24-Jun-2023′,
’25-Jun-2023′]);
tmp = [{’23-Jun-2023 19:00:00′}
{’24-Jun-2023 16:00:00′}
{’24-Jun-2023 11:00:00′}
{’19-Jun-2023 16:00:00′}
{’20-Jun-2023 10:00:00′}
{’21-Jun-2023 10:00:00′}
{’22-Jun-2023 09:00:00′}
{’23-Jun-2023 14:00:00′}
{’19-Jun-2023 17:00:00′}
{’20-Jun-2023 11:00:00′}
{’21-Jun-2023 17:00:00′}
{’22-Jun-2023 15:00:00′}
{’23-Jun-2023 06:00:00′}
{’24-Jun-2023 11:00:00′}
{’25-Jun-2023 19:00:00′}
{’20-Jun-2023 11:00:00′}
{’21-Jun-2023 09:00:00′}
{’23-Jun-2023 12:00:00′}
{’25-Jun-2023 17:00:00′}
{’23-Jun-2023 12:00:00′}
{’22-Jun-2023 07:00:00′}];
B = datetime(tmp, ‘InputFormat’, ‘dd-MMM-yyyy HH:mm:ss’);
ismember(A,B) Is there a (simple) way to use ismember between datetime arrays with different formats?
% Input
A = datetime(…
[’19-Jun-2023′,
’20-Jun-2023′,
’21-Jun-2023′,
’22-Jun-2023′,
’23-Jun-2023′,
’24-Jun-2023′,
’25-Jun-2023′]);
tmp = [{’23-Jun-2023 19:00:00′}
{’24-Jun-2023 16:00:00′}
{’24-Jun-2023 11:00:00′}
{’19-Jun-2023 16:00:00′}
{’20-Jun-2023 10:00:00′}
{’21-Jun-2023 10:00:00′}
{’22-Jun-2023 09:00:00′}
{’23-Jun-2023 14:00:00′}
{’19-Jun-2023 17:00:00′}
{’20-Jun-2023 11:00:00′}
{’21-Jun-2023 17:00:00′}
{’22-Jun-2023 15:00:00′}
{’23-Jun-2023 06:00:00′}
{’24-Jun-2023 11:00:00′}
{’25-Jun-2023 19:00:00′}
{’20-Jun-2023 11:00:00′}
{’21-Jun-2023 09:00:00′}
{’23-Jun-2023 12:00:00′}
{’25-Jun-2023 17:00:00′}
{’23-Jun-2023 12:00:00′}
{’22-Jun-2023 07:00:00′}];
B = datetime(tmp, ‘InputFormat’, ‘dd-MMM-yyyy HH:mm:ss’);
ismember(A,B) ismember, datetime, cell MATLAB Answers — New Questions
I do not know how to make this work??
Im trying to make dynamic variables, based on the names of colums of the tables of some data sets.
This is my Code, the bolded section is my issue
varnammes = ["SpeedGoatT" "imu1_accel_x" "imu1_accel_y" "imu1_accel_z" "imu1_gyro_x" "imu1_gyro_y" "imu1_gyro_z" "imu1_orient_i" "imu1_orient_j" "imu1_orient_k" "imu1_orient_r" "imu2_accel_x" "imu2_accel_y" "imu2_accel_z" "imu2_gyro_x" "imu2_gyro_y" "imu2_gyro_z" "imu2_orient_i" "imu2_orient_j" "imu2_orient_k" "imu2_orient_r" "imu3_accel_x" "imu3_accel_y" "imu3_accel_z" "imu3_gyro_x" "imu3_gyro_y" "imu3_gyro_z" "imu3_orient_i" "imu3_orient_j" "imu3_orient_k" "imu3_orient_r" "imu4_accel_x" "imu4_accel_y" "imu4_accel_z" "imu4_gyro_x" "imu4_gyro_y" "imu4_gyro_z" "imu4_orient_i" "imu4_orient_j" "imu4_orient_k" "imu4_orient_r" "imu5_accel_x" "imu5_accel_y" "imu5_accel_z" "imu5_gyro_x" "imu5_gyro_y" "imu5_gyro_z" "imu5_orient_i" "imu5_orient_j" "imu5_orient_k" "imu5_orient_r" "imu6_accel_x" "imu6_accel_y" "imu6_accel_z" "imu6_gyro_x" "imu6_gyro_y" "imu6_gyro_z" "imu6_orient_i" "imu6_orient_j" "imu6_orient_k" "imu6_orient_r" "imu7_accel_x" "imu7_accel_y" "imu7_accel_z" "imu7_gyro_x" "imu7_gyro_y" "imu7_gyro_z" "imu7_orient_i" "imu7_orient_j" "imu7_orient_k" "imu7_orient_r"];
Tables = struct();
for i = 1:length(files)
load(files(i))
varName = sprintf(‘Table0%d’, i-1); % Create a variable name
Tables.(varName) = logsout.FileLogSignals{4}.Values;% Set the variable in the structure
Tables.(varName) = timeseries2timetable(Tables.(varName));
Tables.(varName) = timetable2table(Tables.(varName));
Tables.(varName) = splitvars(Tables.(varName), 2);
Tables.(varName).Properties.VariableNames(2:end) = varnammes;
for x = 1:length(varnammes)
varName = [char(varnammes(x)) num2str(i-1)];
eval([varName ‘ = x^2;’]);
end
end
This is a test version that is makeing the variables I want but instead of makeing them x^2 i want them to be the column that goes with the variable.
The normal code would be something like
imu1_accel_x = Tables.Table00{:,3};
or
imu1_accel_x = Tables.Table00.imu1_accel_x;
makeing the output being imu1_accel_x0 , with all the values of column imu1_accel_x
I tried makeing the eval line:
eval([varName ‘ = Tables.Table00.imu1_accel_x;’]);
but i got an error and dont know why or how to make it work as inteded
Ive sent an image of the output given the X^2 which works as intended.
Any assistance would be apreciated.Im trying to make dynamic variables, based on the names of colums of the tables of some data sets.
This is my Code, the bolded section is my issue
varnammes = ["SpeedGoatT" "imu1_accel_x" "imu1_accel_y" "imu1_accel_z" "imu1_gyro_x" "imu1_gyro_y" "imu1_gyro_z" "imu1_orient_i" "imu1_orient_j" "imu1_orient_k" "imu1_orient_r" "imu2_accel_x" "imu2_accel_y" "imu2_accel_z" "imu2_gyro_x" "imu2_gyro_y" "imu2_gyro_z" "imu2_orient_i" "imu2_orient_j" "imu2_orient_k" "imu2_orient_r" "imu3_accel_x" "imu3_accel_y" "imu3_accel_z" "imu3_gyro_x" "imu3_gyro_y" "imu3_gyro_z" "imu3_orient_i" "imu3_orient_j" "imu3_orient_k" "imu3_orient_r" "imu4_accel_x" "imu4_accel_y" "imu4_accel_z" "imu4_gyro_x" "imu4_gyro_y" "imu4_gyro_z" "imu4_orient_i" "imu4_orient_j" "imu4_orient_k" "imu4_orient_r" "imu5_accel_x" "imu5_accel_y" "imu5_accel_z" "imu5_gyro_x" "imu5_gyro_y" "imu5_gyro_z" "imu5_orient_i" "imu5_orient_j" "imu5_orient_k" "imu5_orient_r" "imu6_accel_x" "imu6_accel_y" "imu6_accel_z" "imu6_gyro_x" "imu6_gyro_y" "imu6_gyro_z" "imu6_orient_i" "imu6_orient_j" "imu6_orient_k" "imu6_orient_r" "imu7_accel_x" "imu7_accel_y" "imu7_accel_z" "imu7_gyro_x" "imu7_gyro_y" "imu7_gyro_z" "imu7_orient_i" "imu7_orient_j" "imu7_orient_k" "imu7_orient_r"];
Tables = struct();
for i = 1:length(files)
load(files(i))
varName = sprintf(‘Table0%d’, i-1); % Create a variable name
Tables.(varName) = logsout.FileLogSignals{4}.Values;% Set the variable in the structure
Tables.(varName) = timeseries2timetable(Tables.(varName));
Tables.(varName) = timetable2table(Tables.(varName));
Tables.(varName) = splitvars(Tables.(varName), 2);
Tables.(varName).Properties.VariableNames(2:end) = varnammes;
for x = 1:length(varnammes)
varName = [char(varnammes(x)) num2str(i-1)];
eval([varName ‘ = x^2;’]);
end
end
This is a test version that is makeing the variables I want but instead of makeing them x^2 i want them to be the column that goes with the variable.
The normal code would be something like
imu1_accel_x = Tables.Table00{:,3};
or
imu1_accel_x = Tables.Table00.imu1_accel_x;
makeing the output being imu1_accel_x0 , with all the values of column imu1_accel_x
I tried makeing the eval line:
eval([varName ‘ = Tables.Table00.imu1_accel_x;’]);
but i got an error and dont know why or how to make it work as inteded
Ive sent an image of the output given the X^2 which works as intended.
Any assistance would be apreciated. Im trying to make dynamic variables, based on the names of colums of the tables of some data sets.
This is my Code, the bolded section is my issue
varnammes = ["SpeedGoatT" "imu1_accel_x" "imu1_accel_y" "imu1_accel_z" "imu1_gyro_x" "imu1_gyro_y" "imu1_gyro_z" "imu1_orient_i" "imu1_orient_j" "imu1_orient_k" "imu1_orient_r" "imu2_accel_x" "imu2_accel_y" "imu2_accel_z" "imu2_gyro_x" "imu2_gyro_y" "imu2_gyro_z" "imu2_orient_i" "imu2_orient_j" "imu2_orient_k" "imu2_orient_r" "imu3_accel_x" "imu3_accel_y" "imu3_accel_z" "imu3_gyro_x" "imu3_gyro_y" "imu3_gyro_z" "imu3_orient_i" "imu3_orient_j" "imu3_orient_k" "imu3_orient_r" "imu4_accel_x" "imu4_accel_y" "imu4_accel_z" "imu4_gyro_x" "imu4_gyro_y" "imu4_gyro_z" "imu4_orient_i" "imu4_orient_j" "imu4_orient_k" "imu4_orient_r" "imu5_accel_x" "imu5_accel_y" "imu5_accel_z" "imu5_gyro_x" "imu5_gyro_y" "imu5_gyro_z" "imu5_orient_i" "imu5_orient_j" "imu5_orient_k" "imu5_orient_r" "imu6_accel_x" "imu6_accel_y" "imu6_accel_z" "imu6_gyro_x" "imu6_gyro_y" "imu6_gyro_z" "imu6_orient_i" "imu6_orient_j" "imu6_orient_k" "imu6_orient_r" "imu7_accel_x" "imu7_accel_y" "imu7_accel_z" "imu7_gyro_x" "imu7_gyro_y" "imu7_gyro_z" "imu7_orient_i" "imu7_orient_j" "imu7_orient_k" "imu7_orient_r"];
Tables = struct();
for i = 1:length(files)
load(files(i))
varName = sprintf(‘Table0%d’, i-1); % Create a variable name
Tables.(varName) = logsout.FileLogSignals{4}.Values;% Set the variable in the structure
Tables.(varName) = timeseries2timetable(Tables.(varName));
Tables.(varName) = timetable2table(Tables.(varName));
Tables.(varName) = splitvars(Tables.(varName), 2);
Tables.(varName).Properties.VariableNames(2:end) = varnammes;
for x = 1:length(varnammes)
varName = [char(varnammes(x)) num2str(i-1)];
eval([varName ‘ = x^2;’]);
end
end
This is a test version that is makeing the variables I want but instead of makeing them x^2 i want them to be the column that goes with the variable.
The normal code would be something like
imu1_accel_x = Tables.Table00{:,3};
or
imu1_accel_x = Tables.Table00.imu1_accel_x;
makeing the output being imu1_accel_x0 , with all the values of column imu1_accel_x
I tried makeing the eval line:
eval([varName ‘ = Tables.Table00.imu1_accel_x;’]);
but i got an error and dont know why or how to make it work as inteded
Ive sent an image of the output given the X^2 which works as intended.
Any assistance would be apreciated. debug, terrible idea, dynamically named variables, eval MATLAB Answers — New Questions
Regarding choosing correct boundary condition
Hi,
I have a condition where at the left boundary and the right boundary I need the flux to be non-zero.
Thus, the equations
pL + qL*fL = 0 and pr + qr*fr = 0 are such that fL and fr being non zero is making my equation hard to determine the values for pl, ql as well as pr, qr.
Plz tell me how should I approach for the same.
with regards,
rcHi,
I have a condition where at the left boundary and the right boundary I need the flux to be non-zero.
Thus, the equations
pL + qL*fL = 0 and pr + qr*fr = 0 are such that fL and fr being non zero is making my equation hard to determine the values for pl, ql as well as pr, qr.
Plz tell me how should I approach for the same.
with regards,
rc Hi,
I have a condition where at the left boundary and the right boundary I need the flux to be non-zero.
Thus, the equations
pL + qL*fL = 0 and pr + qr*fr = 0 are such that fL and fr being non zero is making my equation hard to determine the values for pl, ql as well as pr, qr.
Plz tell me how should I approach for the same.
with regards,
rc pdepe, boundary conditions MATLAB Answers — New Questions
Relationship between FPGA Sample Frequency, FPGA Clock Frequency, Simulink Solver Rate and Oversampling Factor
Hi, I have a generator controller model in Simulink, I’m hoping to have it deployed on Speedgoat (IO334-325k) and use it to run a real generator. I have five analog input channels and one TTL discrete output channel.
My first question is, am i correct in understanding that the FPGA sample frequency is how fast the FPGA internal signals are sampled? (for example, if i have a discrete transfer function in my model, is it seeing the ‘FPGA sample frequency’ as the sample rate? This is important because discrete transfer functions only work properly at the correct sample rate).
Second question, I read from here (Troubleshooting Real-Time Hardware Deployment Issues in Simscape Hardware-in-the-Loop Workflow – MATLAB & Simulink – MathWorks France) that FPGA sample frequency = FPGA clock frequency/(Oversampling factor x Number of solver iterations), also from here (hdl coder oversampling factor – Google Search) that Oversampling factor = FPGA clock frequency/ Simulink solver rate. Does it mean if the number of solver iterations is 1, then FPGA sample frequency equals the simulink solver rate? I also don’t understand why the simulink solver rate is part of the equation provided that my model only has analog and discrete IOs from/to the outside world, or does it mean in my case, the Oversampling factor = FPGA clock frequency/ ADC rate?
I would really appreciate it if you could help me with the questions above, Thank you very much in advance.
YeungHi, I have a generator controller model in Simulink, I’m hoping to have it deployed on Speedgoat (IO334-325k) and use it to run a real generator. I have five analog input channels and one TTL discrete output channel.
My first question is, am i correct in understanding that the FPGA sample frequency is how fast the FPGA internal signals are sampled? (for example, if i have a discrete transfer function in my model, is it seeing the ‘FPGA sample frequency’ as the sample rate? This is important because discrete transfer functions only work properly at the correct sample rate).
Second question, I read from here (Troubleshooting Real-Time Hardware Deployment Issues in Simscape Hardware-in-the-Loop Workflow – MATLAB & Simulink – MathWorks France) that FPGA sample frequency = FPGA clock frequency/(Oversampling factor x Number of solver iterations), also from here (hdl coder oversampling factor – Google Search) that Oversampling factor = FPGA clock frequency/ Simulink solver rate. Does it mean if the number of solver iterations is 1, then FPGA sample frequency equals the simulink solver rate? I also don’t understand why the simulink solver rate is part of the equation provided that my model only has analog and discrete IOs from/to the outside world, or does it mean in my case, the Oversampling factor = FPGA clock frequency/ ADC rate?
I would really appreciate it if you could help me with the questions above, Thank you very much in advance.
Yeung Hi, I have a generator controller model in Simulink, I’m hoping to have it deployed on Speedgoat (IO334-325k) and use it to run a real generator. I have five analog input channels and one TTL discrete output channel.
My first question is, am i correct in understanding that the FPGA sample frequency is how fast the FPGA internal signals are sampled? (for example, if i have a discrete transfer function in my model, is it seeing the ‘FPGA sample frequency’ as the sample rate? This is important because discrete transfer functions only work properly at the correct sample rate).
Second question, I read from here (Troubleshooting Real-Time Hardware Deployment Issues in Simscape Hardware-in-the-Loop Workflow – MATLAB & Simulink – MathWorks France) that FPGA sample frequency = FPGA clock frequency/(Oversampling factor x Number of solver iterations), also from here (hdl coder oversampling factor – Google Search) that Oversampling factor = FPGA clock frequency/ Simulink solver rate. Does it mean if the number of solver iterations is 1, then FPGA sample frequency equals the simulink solver rate? I also don’t understand why the simulink solver rate is part of the equation provided that my model only has analog and discrete IOs from/to the outside world, or does it mean in my case, the Oversampling factor = FPGA clock frequency/ ADC rate?
I would really appreciate it if you could help me with the questions above, Thank you very much in advance.
Yeung hdl coder, fpga, speedgoat, oversampling, fpga sample frequency MATLAB Answers — New Questions
Execute a Matlab script from Docker container
Hello,
I have a very basic matlab file called hello_world.m that just create a simple .csv file. My goal is now to try to execute this matlab script from a Docker container. This is my Dockerfile:
FROM mathworks/matlab:r2024a
ENV MLM_LICENSE_FILE /licenses
USER root
RUN mkdir -p /licenses /matlab_script
COPY license.lic /licenses/license.lic
COPY hello_world.m /matlab_script/hello_world.m
WORKDIR /matlab_script
CMD ["matlab", "-batch", "hello_world"]
The license.lic attatched is a "DEMO" license.
This is the command I use to run my container:
docker run –rm -v $(pwd)/license.lic:/licenses/license.lic matlab-demo
Error l
ogs:
License checkout failed.
License Manager Error -9
Your username does not match the username in the license file.
To run on this computer, you must run the Activation client to reactivate your license.
Is it because I am using a "demo"license?Hello,
I have a very basic matlab file called hello_world.m that just create a simple .csv file. My goal is now to try to execute this matlab script from a Docker container. This is my Dockerfile:
FROM mathworks/matlab:r2024a
ENV MLM_LICENSE_FILE /licenses
USER root
RUN mkdir -p /licenses /matlab_script
COPY license.lic /licenses/license.lic
COPY hello_world.m /matlab_script/hello_world.m
WORKDIR /matlab_script
CMD ["matlab", "-batch", "hello_world"]
The license.lic attatched is a "DEMO" license.
This is the command I use to run my container:
docker run –rm -v $(pwd)/license.lic:/licenses/license.lic matlab-demo
Error l
ogs:
License checkout failed.
License Manager Error -9
Your username does not match the username in the license file.
To run on this computer, you must run the Activation client to reactivate your license.
Is it because I am using a "demo"license? Hello,
I have a very basic matlab file called hello_world.m that just create a simple .csv file. My goal is now to try to execute this matlab script from a Docker container. This is my Dockerfile:
FROM mathworks/matlab:r2024a
ENV MLM_LICENSE_FILE /licenses
USER root
RUN mkdir -p /licenses /matlab_script
COPY license.lic /licenses/license.lic
COPY hello_world.m /matlab_script/hello_world.m
WORKDIR /matlab_script
CMD ["matlab", "-batch", "hello_world"]
The license.lic attatched is a "DEMO" license.
This is the command I use to run my container:
docker run –rm -v $(pwd)/license.lic:/licenses/license.lic matlab-demo
Error l
ogs:
License checkout failed.
License Manager Error -9
Your username does not match the username in the license file.
To run on this computer, you must run the Activation client to reactivate your license.
Is it because I am using a "demo"license? matlab, docker MATLAB Answers — New Questions
How to extract and input arrays from simscape to plot them
In short if i have simple model like this mass-spring system and i want to input an array of spring constant values in the spring constant block and see how the maximum distance change and graph that relation in order to determine something.
Of course thats just for illustration purposes my model on simscape is more complicated than that but i want to know how can i even begin doing something like this, to input an array of values into a simscape block and simulate as many times as array dimension without doing it manually.
I Already know how to extract the data from a signal using to workspace block but this specific task i cant figure it out.In short if i have simple model like this mass-spring system and i want to input an array of spring constant values in the spring constant block and see how the maximum distance change and graph that relation in order to determine something.
Of course thats just for illustration purposes my model on simscape is more complicated than that but i want to know how can i even begin doing something like this, to input an array of values into a simscape block and simulate as many times as array dimension without doing it manually.
I Already know how to extract the data from a signal using to workspace block but this specific task i cant figure it out. In short if i have simple model like this mass-spring system and i want to input an array of spring constant values in the spring constant block and see how the maximum distance change and graph that relation in order to determine something.
Of course thats just for illustration purposes my model on simscape is more complicated than that but i want to know how can i even begin doing something like this, to input an array of values into a simscape block and simulate as many times as array dimension without doing it manually.
I Already know how to extract the data from a signal using to workspace block but this specific task i cant figure it out. matlab, simscape MATLAB Answers — New Questions
Can not use arrays of ui components in app desiger
I am using the app designer to create an app with quite a lot of properties here is a smal sample:
MemValue_1_1 matlab.ui.control.EditField
MemValue_1_2 matlab.ui.control.EditField
MemValue_1_3 matlab.ui.control.EditField
MemValue_1_4 matlab.ui.control.EditField
MemValue_1_5 matlab.ui.control.EditField
MemValue_1_6 matlab.ui.control.EditField
MemValue_1_7 matlab.ui.control.EditField
MemValue_1_8 matlab.ui.control.EditField
MemValue_1_9 matlab.ui.control.EditField
MemValue_1_10 matlab.ui.control.EditField
MemValue_1_11 matlab.ui.control.EditField
MemValue_1_12 matlab.ui.control.EditField
MemValue_1_13 matlab.ui.control.EditField
MemValue_1_14 matlab.ui.control.EditField
MemValue_1_15 matlab.ui.control.EditField
MemValue_1_16 matlab.ui.control.EditField
MemValue_1_17 matlab.ui.control.EditField
MemValue_1_18 matlab.ui.control.EditField
MemValue_1_19 matlab.ui.control.EditField
MemValue_1_20 matlab.ui.control.EditField
MemValue_1_21 matlab.ui.control.EditField
MemValue_1_22 matlab.ui.control.EditField
MemValue_1_23 matlab.ui.control.EditField
MemValue_1_24 matlab.ui.control.EditField
MemValue_1_25 matlab.ui.control.EditField
MemValue_1_26 matlab.ui.control.EditField
MemValue_1_27 matlab.ui.control.EditField
MemValue_1_28 matlab.ui.control.EditField
MemValue_1_29 matlab.ui.control.EditField
MemValue_1_30 matlab.ui.control.EditField
MemValue_1_31 matlab.ui.control.EditField
MemValue_1_32 matlab.ui.control.EditField
MemValue_1_33 matlab.ui.control.EditField
MemValue_1_34 matlab.ui.control.EditField
MemValue_1_35 matlab.ui.control.EditField
MemValue_1_36 matlab.ui.control.EditField
MemValue_1_37 matlab.ui.control.EditField
MemValue_1_38 matlab.ui.control.EditField
MemValue_1_39 matlab.ui.control.EditField
MemValue_1_40 matlab.ui.control.EditField
MemValue_1_41 matlab.ui.control.EditField
MemValue_1_42 matlab.ui.control.EditField
MemValue_1_43 matlab.ui.control.EditField
MemValue_1_44 matlab.ui.control.EditField
MemValue_1_45 matlab.ui.control.EditField
MemValue_1_46 matlab.ui.control.EditField
MemValue_1_47 matlab.ui.control.EditField
MemValue_1_48 matlab.ui.control.EditField
MemValue_1_49 matlab.ui.control.EditField
MemValue_1_50 matlab.ui.control.EditField
MemValue_1_51 matlab.ui.control.EditField
MemValue_1_52 matlab.ui.control.EditField
MemValue_1_53 matlab.ui.control.EditField
MemValue_1_54 matlab.ui.control.EditField
MemValue_1_55 matlab.ui.control.EditField
MemValue_1_56 matlab.ui.control.EditField
MemValue_1_57 matlab.ui.control.EditField
MemValue_1_58 matlab.ui.control.EditField
MemValue_1_59 matlab.ui.control.EditField
MemValue_1_60 matlab.ui.control.EditField
MemValue_1_61 matlab.ui.control.EditField
MemValue_1_62 matlab.ui.control.EditField
MemValue_1_63 matlab.ui.control.EditField
MemValue_1_64 matlab.ui.control.EditField
It should be very ovious that this is bad code and I would like to use an array of MemValues but sadly due to the restrictions of the app designer I can not do that since I would need to modify the code that is not editable in the app designer. Is there any way to solve this issue?
Btw: I know that I can export to .m file where I could do that but I can not reconvert that to the .mlapp fileI am using the app designer to create an app with quite a lot of properties here is a smal sample:
MemValue_1_1 matlab.ui.control.EditField
MemValue_1_2 matlab.ui.control.EditField
MemValue_1_3 matlab.ui.control.EditField
MemValue_1_4 matlab.ui.control.EditField
MemValue_1_5 matlab.ui.control.EditField
MemValue_1_6 matlab.ui.control.EditField
MemValue_1_7 matlab.ui.control.EditField
MemValue_1_8 matlab.ui.control.EditField
MemValue_1_9 matlab.ui.control.EditField
MemValue_1_10 matlab.ui.control.EditField
MemValue_1_11 matlab.ui.control.EditField
MemValue_1_12 matlab.ui.control.EditField
MemValue_1_13 matlab.ui.control.EditField
MemValue_1_14 matlab.ui.control.EditField
MemValue_1_15 matlab.ui.control.EditField
MemValue_1_16 matlab.ui.control.EditField
MemValue_1_17 matlab.ui.control.EditField
MemValue_1_18 matlab.ui.control.EditField
MemValue_1_19 matlab.ui.control.EditField
MemValue_1_20 matlab.ui.control.EditField
MemValue_1_21 matlab.ui.control.EditField
MemValue_1_22 matlab.ui.control.EditField
MemValue_1_23 matlab.ui.control.EditField
MemValue_1_24 matlab.ui.control.EditField
MemValue_1_25 matlab.ui.control.EditField
MemValue_1_26 matlab.ui.control.EditField
MemValue_1_27 matlab.ui.control.EditField
MemValue_1_28 matlab.ui.control.EditField
MemValue_1_29 matlab.ui.control.EditField
MemValue_1_30 matlab.ui.control.EditField
MemValue_1_31 matlab.ui.control.EditField
MemValue_1_32 matlab.ui.control.EditField
MemValue_1_33 matlab.ui.control.EditField
MemValue_1_34 matlab.ui.control.EditField
MemValue_1_35 matlab.ui.control.EditField
MemValue_1_36 matlab.ui.control.EditField
MemValue_1_37 matlab.ui.control.EditField
MemValue_1_38 matlab.ui.control.EditField
MemValue_1_39 matlab.ui.control.EditField
MemValue_1_40 matlab.ui.control.EditField
MemValue_1_41 matlab.ui.control.EditField
MemValue_1_42 matlab.ui.control.EditField
MemValue_1_43 matlab.ui.control.EditField
MemValue_1_44 matlab.ui.control.EditField
MemValue_1_45 matlab.ui.control.EditField
MemValue_1_46 matlab.ui.control.EditField
MemValue_1_47 matlab.ui.control.EditField
MemValue_1_48 matlab.ui.control.EditField
MemValue_1_49 matlab.ui.control.EditField
MemValue_1_50 matlab.ui.control.EditField
MemValue_1_51 matlab.ui.control.EditField
MemValue_1_52 matlab.ui.control.EditField
MemValue_1_53 matlab.ui.control.EditField
MemValue_1_54 matlab.ui.control.EditField
MemValue_1_55 matlab.ui.control.EditField
MemValue_1_56 matlab.ui.control.EditField
MemValue_1_57 matlab.ui.control.EditField
MemValue_1_58 matlab.ui.control.EditField
MemValue_1_59 matlab.ui.control.EditField
MemValue_1_60 matlab.ui.control.EditField
MemValue_1_61 matlab.ui.control.EditField
MemValue_1_62 matlab.ui.control.EditField
MemValue_1_63 matlab.ui.control.EditField
MemValue_1_64 matlab.ui.control.EditField
It should be very ovious that this is bad code and I would like to use an array of MemValues but sadly due to the restrictions of the app designer I can not do that since I would need to modify the code that is not editable in the app designer. Is there any way to solve this issue?
Btw: I know that I can export to .m file where I could do that but I can not reconvert that to the .mlapp file I am using the app designer to create an app with quite a lot of properties here is a smal sample:
MemValue_1_1 matlab.ui.control.EditField
MemValue_1_2 matlab.ui.control.EditField
MemValue_1_3 matlab.ui.control.EditField
MemValue_1_4 matlab.ui.control.EditField
MemValue_1_5 matlab.ui.control.EditField
MemValue_1_6 matlab.ui.control.EditField
MemValue_1_7 matlab.ui.control.EditField
MemValue_1_8 matlab.ui.control.EditField
MemValue_1_9 matlab.ui.control.EditField
MemValue_1_10 matlab.ui.control.EditField
MemValue_1_11 matlab.ui.control.EditField
MemValue_1_12 matlab.ui.control.EditField
MemValue_1_13 matlab.ui.control.EditField
MemValue_1_14 matlab.ui.control.EditField
MemValue_1_15 matlab.ui.control.EditField
MemValue_1_16 matlab.ui.control.EditField
MemValue_1_17 matlab.ui.control.EditField
MemValue_1_18 matlab.ui.control.EditField
MemValue_1_19 matlab.ui.control.EditField
MemValue_1_20 matlab.ui.control.EditField
MemValue_1_21 matlab.ui.control.EditField
MemValue_1_22 matlab.ui.control.EditField
MemValue_1_23 matlab.ui.control.EditField
MemValue_1_24 matlab.ui.control.EditField
MemValue_1_25 matlab.ui.control.EditField
MemValue_1_26 matlab.ui.control.EditField
MemValue_1_27 matlab.ui.control.EditField
MemValue_1_28 matlab.ui.control.EditField
MemValue_1_29 matlab.ui.control.EditField
MemValue_1_30 matlab.ui.control.EditField
MemValue_1_31 matlab.ui.control.EditField
MemValue_1_32 matlab.ui.control.EditField
MemValue_1_33 matlab.ui.control.EditField
MemValue_1_34 matlab.ui.control.EditField
MemValue_1_35 matlab.ui.control.EditField
MemValue_1_36 matlab.ui.control.EditField
MemValue_1_37 matlab.ui.control.EditField
MemValue_1_38 matlab.ui.control.EditField
MemValue_1_39 matlab.ui.control.EditField
MemValue_1_40 matlab.ui.control.EditField
MemValue_1_41 matlab.ui.control.EditField
MemValue_1_42 matlab.ui.control.EditField
MemValue_1_43 matlab.ui.control.EditField
MemValue_1_44 matlab.ui.control.EditField
MemValue_1_45 matlab.ui.control.EditField
MemValue_1_46 matlab.ui.control.EditField
MemValue_1_47 matlab.ui.control.EditField
MemValue_1_48 matlab.ui.control.EditField
MemValue_1_49 matlab.ui.control.EditField
MemValue_1_50 matlab.ui.control.EditField
MemValue_1_51 matlab.ui.control.EditField
MemValue_1_52 matlab.ui.control.EditField
MemValue_1_53 matlab.ui.control.EditField
MemValue_1_54 matlab.ui.control.EditField
MemValue_1_55 matlab.ui.control.EditField
MemValue_1_56 matlab.ui.control.EditField
MemValue_1_57 matlab.ui.control.EditField
MemValue_1_58 matlab.ui.control.EditField
MemValue_1_59 matlab.ui.control.EditField
MemValue_1_60 matlab.ui.control.EditField
MemValue_1_61 matlab.ui.control.EditField
MemValue_1_62 matlab.ui.control.EditField
MemValue_1_63 matlab.ui.control.EditField
MemValue_1_64 matlab.ui.control.EditField
It should be very ovious that this is bad code and I would like to use an array of MemValues but sadly due to the restrictions of the app designer I can not do that since I would need to modify the code that is not editable in the app designer. Is there any way to solve this issue?
Btw: I know that I can export to .m file where I could do that but I can not reconvert that to the .mlapp file appdesigner, array MATLAB Answers — New Questions
Simscape block parameter, change dynamically during simulation
Hallo,
is it possible to change a parameter of a Simscape block during simulation time?
Example: I want to change the thermal conductivity of the "Conductive Heat Transfer" block during the simulation time.
Example:
<</matlabcentral/answers/uploaded_files/85080/model_simcape.PNG>>
The thermal conductivity depends on the transferred heat and the temperature of the sink. For this I have a lookup table or a variable in workspace. Is it possible to check after each iteration the heat from the "Ideal Heat Flow Sensor" and the sink temperature and then send the new thermal conductivity to the "Conductive Heat Transfer" block for the next iteration?Hallo,
is it possible to change a parameter of a Simscape block during simulation time?
Example: I want to change the thermal conductivity of the "Conductive Heat Transfer" block during the simulation time.
Example:
<</matlabcentral/answers/uploaded_files/85080/model_simcape.PNG>>
The thermal conductivity depends on the transferred heat and the temperature of the sink. For this I have a lookup table or a variable in workspace. Is it possible to check after each iteration the heat from the "Ideal Heat Flow Sensor" and the sink temperature and then send the new thermal conductivity to the "Conductive Heat Transfer" block for the next iteration? Hallo,
is it possible to change a parameter of a Simscape block during simulation time?
Example: I want to change the thermal conductivity of the "Conductive Heat Transfer" block during the simulation time.
Example:
<</matlabcentral/answers/uploaded_files/85080/model_simcape.PNG>>
The thermal conductivity depends on the transferred heat and the temperature of the sink. For this I have a lookup table or a variable in workspace. Is it possible to check after each iteration the heat from the "Ideal Heat Flow Sensor" and the sink temperature and then send the new thermal conductivity to the "Conductive Heat Transfer" block for the next iteration? simscape, simulink, thermal, change parameter dynamically, matlab MATLAB Answers — New Questions
How to normalize a single row wise in MACONT, or multiply equation to single column only
I am making a code for MACONT and using 3 normalization technique, I am unable to normalization single column with their respective value (0-1) eventually ended up normalizing the the whole data from 0-1
Or is this possible to mulitpy a certain equation to one coloumn only without extracting itI am making a code for MACONT and using 3 normalization technique, I am unable to normalization single column with their respective value (0-1) eventually ended up normalizing the the whole data from 0-1
Or is this possible to mulitpy a certain equation to one coloumn only without extracting it I am making a code for MACONT and using 3 normalization technique, I am unable to normalization single column with their respective value (0-1) eventually ended up normalizing the the whole data from 0-1
Or is this possible to mulitpy a certain equation to one coloumn only without extracting it macont MATLAB Answers — New Questions
Using matlab from local computer to connect and transfer files to remote computer
Hello all,
I am trying to write a script to login to a remote computer, transfer the local files, and run some programs on the remote computer. I am using a linux system and I am able to login to the remote computer (also linux) using the unix(‘ssh -Y username@hostname’) matlab command, but once I login, the commands written in the editor after this do not execute. For example, I would like to execute the print working directory (pwd) command after logging in to the remote computer.
Script I have written in the editor for the login and pwd command:
unix(‘ssh -Y username@hostname’);
unix(‘pwd’);
What the matlab command window shows me:
>> script
username@hostname’s Password: *enter password in command window*
username@hostname-login2:~>
Now the unix(‘pwd’) command does not seem to execute in the username@hostname-login2:~>
To execute the pwd command, I would have to go to the command window and type it. My question is how do I write the script in the matlab editor so that the pwd command is executed from the editor itself when running the script?
Let me know if you need additional details. Thanks in advance for your help.
Regards,
SouHello all,
I am trying to write a script to login to a remote computer, transfer the local files, and run some programs on the remote computer. I am using a linux system and I am able to login to the remote computer (also linux) using the unix(‘ssh -Y username@hostname’) matlab command, but once I login, the commands written in the editor after this do not execute. For example, I would like to execute the print working directory (pwd) command after logging in to the remote computer.
Script I have written in the editor for the login and pwd command:
unix(‘ssh -Y username@hostname’);
unix(‘pwd’);
What the matlab command window shows me:
>> script
username@hostname’s Password: *enter password in command window*
username@hostname-login2:~>
Now the unix(‘pwd’) command does not seem to execute in the username@hostname-login2:~>
To execute the pwd command, I would have to go to the command window and type it. My question is how do I write the script in the matlab editor so that the pwd command is executed from the editor itself when running the script?
Let me know if you need additional details. Thanks in advance for your help.
Regards,
Sou Hello all,
I am trying to write a script to login to a remote computer, transfer the local files, and run some programs on the remote computer. I am using a linux system and I am able to login to the remote computer (also linux) using the unix(‘ssh -Y username@hostname’) matlab command, but once I login, the commands written in the editor after this do not execute. For example, I would like to execute the print working directory (pwd) command after logging in to the remote computer.
Script I have written in the editor for the login and pwd command:
unix(‘ssh -Y username@hostname’);
unix(‘pwd’);
What the matlab command window shows me:
>> script
username@hostname’s Password: *enter password in command window*
username@hostname-login2:~>
Now the unix(‘pwd’) command does not seem to execute in the username@hostname-login2:~>
To execute the pwd command, I would have to go to the command window and type it. My question is how do I write the script in the matlab editor so that the pwd command is executed from the editor itself when running the script?
Let me know if you need additional details. Thanks in advance for your help.
Regards,
Sou ssh remote login, unix command MATLAB Answers — New Questions
Mass spring damper system problem
Hello, I am designing the mass spring damper system in the image. I am creating this code for the design of a ship crane. In my road equation, there is an increase of approximately 20 meters, and the spring k_c is stretched by 20 meters. I just want the spring to follow the road, but the spring follows the road like an arrow, which is very high like 2000N/mm². Stress occurs. I think there is a mistake in my input equation, but I couldn’t figure it out completely. I would be very happy if you could help me
The image of the system is also attached.
Matlab code:
"% System parameters
M_c = 917; % Mass of the crane boom (kg)
M_s = 87; % Mass of the shock absorber (kg)
M_WL = 4075; % Mass of the working load (kg)
k_c = 554376; % Spring constant of the crane + crane hook ropes (N/m)
k_s = 24162; % Spring constant of the shock absorber system (N/m)
k_R = 9090572; % Spring constant of the lifting beam and lower rope (N/m)
c_s = 5800; % Damping constant of the shock absorber system (Ns/m)
A = 1.5; % Amplitude of input signal (m)
omega = 1; % Angular frequency of input signal (rad/s)
V_H1 = 0.69; % Linear term coefficient for first interval (m/s)
V_H2 = 0; % Linear term coefficient for second interval (m/s)
V_H3 = -0.1; % Linear term coefficient for third interval (m/s)
d_c = 0.026; % Diameter of spring kc (m)
d_s = 0.03; % Diameter of spring ks (m)
d_R = 0.0226; % Diameter of spring kR (m)
% Combined time vector with smaller sampling period
t = 0:0.01:45; % From 0 to 45 seconds with 0.01s sampling period
% Input signal (m)
u = zeros(size(t));
u(t <= 25) = A * sin(omega * t(t <= 25)) + V_H1 * t(t <= 25);
u(t > 25 & t <= 35) = A * sin(omega * t(t > 25 & t <= 35)) + V_H1 * 25 + V_H2 * (t(t > 25 & t <= 35) – 25);
u(t > 35) = A * sin(omega * t(t > 35)) + V_H1 * 25 + V_H3 * (t(t > 35) – 35);
% State-space matrix
A_matrix = [0 1 0 0 0 0;
-k_c/M_c -c_s/M_c k_s/M_c c_s/M_c 0 0;
0 0 0 1 0 0;
k_s/M_s c_s/M_s -(k_s+k_R)/M_s -c_s/M_s k_R/M_s 0;
0 0 0 0 0 1;
0 0 k_R/M_WL 0 -k_R/M_WL 0];
B_matrix = [0;
k_c/M_c;
0;
0;
0;
0];
C_matrix = [1 0 0 0 0 0;
0 0 1 0 0 0;
0 0 0 0 1 0];
D_matrix = [0;
0;
0];
% Create state-space model
sys = ss(A_matrix, B_matrix, C_matrix, D_matrix);
% Simulate system response
[y, t, x] = lsim(sys, u, t);
% Calculate spring extensions (m)
delta_kc = u’- y(:,1); % Extension of spring kc
delta_ks = y(:,1) – y(:,2); % Extension of spring ks
delta_kR = y(:,2) – y(:,3); % Extension of spring kR
% Convert spring extensions to meters (m)
delta_kc_m = delta_kc; % Assuming input signal u is in meters
delta_ks_m = delta_ks; % Assuming displacements are in meters
delta_kR_m = delta_kR; % Assuming displacements are in meters
% Calculate spring stresses (N/m²)
A_c = pi * (d_c/2)^2; % Cross-sectional area of spring kc (m²)
A_s = pi * (d_s/2)^2; % Cross-sectional area of spring ks (m²)
A_R = pi * (d_R/2)^2; % Cross-sectional area of spring kR (m²)
F_kc = k_c * delta_kc_m; % Force in spring kc (N)
F_ks = k_s * delta_ks_m; % Force in spring ks (N)
F_kR = k_R * delta_kR_m; % Force in spring kR (N)
sigma_kc = F_kc / A_c; % Stress in spring kc (N/m²)
sigma_ks = F_ks / A_s; % Stress in spring ks (N/m²)
sigma_kR = F_kR / A_R; % Stress in spring kR (N/m²)
% Convert stress to N/mm²
sigma_kc_mm2 = sigma_kc * 1e-6;
sigma_ks_mm2 = sigma_ks * 1e-6;
sigma_kR_mm2 = sigma_kR * 1e-6;
% Plot input signal and outputs
figure;
subplot(5,1,1);
plot(t, u);
title(‘Input Signal u’);
xlabel(‘Time (s)’);
ylabel(‘u (m)’);
subplot(5,1,2);
plot(t, y(:,1));
title(‘Output y1’);
xlabel(‘Time (s)’);
ylabel(‘y1 (m)’);
subplot(5,1,3);
plot(t, y(:,2));
title(‘Output y2’);
xlabel(‘Time (s)’);
ylabel(‘y2 (m)’);
subplot(5,1,4);
plot(t, y(:,3));
title(‘Output y3’);
xlabel(‘Time (s)’);
ylabel(‘y3 (m)’);
% Plot spring stresses in separate figures
subplot(5,1,5);
hold on;
plot(t, sigma_kc_mm2, ‘r’);
plot(t, sigma_ks_mm2, ‘g’);
plot(t, sigma_kR_mm2, ‘b’);
title(‘Stress in Springs’);
xlabel(‘Time (s)’);
ylabel(‘Stress (N/mm²)’);
legend(‘Stress sigma_{kc}’, ‘Stress sigma_{ks}’, ‘Stress sigma_{kR}’);
grid on;
% Animation
figure;
% Define positions of masses and springs
y1_base = 2; % Base position of mass 1 (m)
y2_base = 1; % Base position of mass 2 (m)
y3_base = 0; % Base position of mass 3 (m)
% Plot settings
axis([-0.5 1.5 -1 30]);
hold on;
% Initial positions of masses
h_m1 = rectangle(‘Position’,[0.4 y1_base + y(1,1) 0.2 0.2], ‘Curvature’, [0.1 0.1], ‘FaceColor’, ‘blue’);
h_m2 = rectangle(‘Position’,[0.4 y2_base + y(1,2) 0.2 0.2], ‘Curvature’, [0.1 0.1], ‘FaceColor’, ‘green’);
h_m3 = rectangle(‘Position’,[0.4 y3_base + y(1,3) 0.2 0.2], ‘Curvature’, [0.1 0.1], ‘FaceColor’, ‘red’);
% Labels for masses
text(0.65, y1_base + y(1,1) + 0.1, ‘M_c’, ‘FontSize’, 12, ‘Color’, ‘blue’);
text(0.65, y2_base + y(1,2) + 0.1, ‘M_s’, ‘FontSize’, 12, ‘Color’, ‘green’);
text(0.65, y3_base + y(1,3) + 0.1, ‘M_{WL}’, ‘FontSize’, 12, ‘Color’, ‘red’);
% Initial positions of springs
h_spring1 = plot([0.5 0.5], [3 y1_base + y(1,1) + 0.2], ‘k’, ‘LineWidth’, 2);
h_spring2 = plot([0.5 0.5], [y1_base + y(1,1) y2_base + y(1,2) + 0.2], ‘k’, ‘LineWidth’, 2);
h_spring3 = plot([0.5 0.5], [y2_base + y(1,2) y3_base + y(1,3) + 0.2], ‘k’, ‘LineWidth’, 2);
% Labels for springs and dampers
text(0.3, 2.5, ‘k_c’, ‘FontSize’, 12, ‘Color’, ‘black’);
text(0.3, 1.5, ‘k_s’, ‘FontSize’, 12, ‘Color’, ‘black’);
text(0.3, 0.5, ‘k_R’, ‘FontSize’, 12, ‘Color’, ‘black’);
text(0.7, y1_base + (y2_base – y1_base) / 2 + y(1,1) / 2 + y(1,2) / 2, ‘c_s’, ‘FontSize’, 12, ‘Color’, ‘black’);
% Initial position of the damper
h_damper = plot([0.45 0.55], [y1_base + (y2_base – y1_base) / 2 + y(1,1) / 2 + y(1,2) / 2 y1_base + (y2_base – y1_base) / 2 + y(1,1) / 2 + y(1,2) / 2], ‘k’, ‘LineWidth’, 6);
% Animation loop
for i = 1:length(t)
% Update positions of masses
if isvalid(h_m1)
set(h_m1, ‘Position’, [0.4 y1_base + y(i,1) 0.2 0.2]);
end
if isvalid(h_m2)
set(h_m2, ‘Position’, [0.4 y2_base + y(i,2) 0.2 0.2]);
end
if isvalid(h_m3)
set(h_m3, ‘Position’, [0.4 y3_base + y(i,3) 0.2 0.2]);
end
% Update positions of springs
if isvalid(h_spring1)
set(h_spring1, ‘YData’, [3 y1_base + y(i,1) + 0.2]);
end
if isvalid(h_spring2)
set(h_spring2, ‘YData’, [y1_base + y(i,1) y2_base + y(i,2) + 0.2]);
end
if isvalid(h_spring3)
set(h_spring3, ‘YData’, [y2_base + y(i,2) y3_base + y(i,3) + 0.2]);
end
% Update position of the damper
if isvalid(h_damper)
set(h_damper, ‘YData’, [y1_base + (y2_base – y1_base) / 2 + y(i,1) / 2 + y(i,2) / 2 y1_base + (y2_base – y1_base) / 2 + y(i,1) / 2 + y(i,2) / 2]);
end
% Pause to create animation effect
pause(0.01);
end
hold off;
"Hello, I am designing the mass spring damper system in the image. I am creating this code for the design of a ship crane. In my road equation, there is an increase of approximately 20 meters, and the spring k_c is stretched by 20 meters. I just want the spring to follow the road, but the spring follows the road like an arrow, which is very high like 2000N/mm². Stress occurs. I think there is a mistake in my input equation, but I couldn’t figure it out completely. I would be very happy if you could help me
The image of the system is also attached.
Matlab code:
"% System parameters
M_c = 917; % Mass of the crane boom (kg)
M_s = 87; % Mass of the shock absorber (kg)
M_WL = 4075; % Mass of the working load (kg)
k_c = 554376; % Spring constant of the crane + crane hook ropes (N/m)
k_s = 24162; % Spring constant of the shock absorber system (N/m)
k_R = 9090572; % Spring constant of the lifting beam and lower rope (N/m)
c_s = 5800; % Damping constant of the shock absorber system (Ns/m)
A = 1.5; % Amplitude of input signal (m)
omega = 1; % Angular frequency of input signal (rad/s)
V_H1 = 0.69; % Linear term coefficient for first interval (m/s)
V_H2 = 0; % Linear term coefficient for second interval (m/s)
V_H3 = -0.1; % Linear term coefficient for third interval (m/s)
d_c = 0.026; % Diameter of spring kc (m)
d_s = 0.03; % Diameter of spring ks (m)
d_R = 0.0226; % Diameter of spring kR (m)
% Combined time vector with smaller sampling period
t = 0:0.01:45; % From 0 to 45 seconds with 0.01s sampling period
% Input signal (m)
u = zeros(size(t));
u(t <= 25) = A * sin(omega * t(t <= 25)) + V_H1 * t(t <= 25);
u(t > 25 & t <= 35) = A * sin(omega * t(t > 25 & t <= 35)) + V_H1 * 25 + V_H2 * (t(t > 25 & t <= 35) – 25);
u(t > 35) = A * sin(omega * t(t > 35)) + V_H1 * 25 + V_H3 * (t(t > 35) – 35);
% State-space matrix
A_matrix = [0 1 0 0 0 0;
-k_c/M_c -c_s/M_c k_s/M_c c_s/M_c 0 0;
0 0 0 1 0 0;
k_s/M_s c_s/M_s -(k_s+k_R)/M_s -c_s/M_s k_R/M_s 0;
0 0 0 0 0 1;
0 0 k_R/M_WL 0 -k_R/M_WL 0];
B_matrix = [0;
k_c/M_c;
0;
0;
0;
0];
C_matrix = [1 0 0 0 0 0;
0 0 1 0 0 0;
0 0 0 0 1 0];
D_matrix = [0;
0;
0];
% Create state-space model
sys = ss(A_matrix, B_matrix, C_matrix, D_matrix);
% Simulate system response
[y, t, x] = lsim(sys, u, t);
% Calculate spring extensions (m)
delta_kc = u’- y(:,1); % Extension of spring kc
delta_ks = y(:,1) – y(:,2); % Extension of spring ks
delta_kR = y(:,2) – y(:,3); % Extension of spring kR
% Convert spring extensions to meters (m)
delta_kc_m = delta_kc; % Assuming input signal u is in meters
delta_ks_m = delta_ks; % Assuming displacements are in meters
delta_kR_m = delta_kR; % Assuming displacements are in meters
% Calculate spring stresses (N/m²)
A_c = pi * (d_c/2)^2; % Cross-sectional area of spring kc (m²)
A_s = pi * (d_s/2)^2; % Cross-sectional area of spring ks (m²)
A_R = pi * (d_R/2)^2; % Cross-sectional area of spring kR (m²)
F_kc = k_c * delta_kc_m; % Force in spring kc (N)
F_ks = k_s * delta_ks_m; % Force in spring ks (N)
F_kR = k_R * delta_kR_m; % Force in spring kR (N)
sigma_kc = F_kc / A_c; % Stress in spring kc (N/m²)
sigma_ks = F_ks / A_s; % Stress in spring ks (N/m²)
sigma_kR = F_kR / A_R; % Stress in spring kR (N/m²)
% Convert stress to N/mm²
sigma_kc_mm2 = sigma_kc * 1e-6;
sigma_ks_mm2 = sigma_ks * 1e-6;
sigma_kR_mm2 = sigma_kR * 1e-6;
% Plot input signal and outputs
figure;
subplot(5,1,1);
plot(t, u);
title(‘Input Signal u’);
xlabel(‘Time (s)’);
ylabel(‘u (m)’);
subplot(5,1,2);
plot(t, y(:,1));
title(‘Output y1’);
xlabel(‘Time (s)’);
ylabel(‘y1 (m)’);
subplot(5,1,3);
plot(t, y(:,2));
title(‘Output y2’);
xlabel(‘Time (s)’);
ylabel(‘y2 (m)’);
subplot(5,1,4);
plot(t, y(:,3));
title(‘Output y3’);
xlabel(‘Time (s)’);
ylabel(‘y3 (m)’);
% Plot spring stresses in separate figures
subplot(5,1,5);
hold on;
plot(t, sigma_kc_mm2, ‘r’);
plot(t, sigma_ks_mm2, ‘g’);
plot(t, sigma_kR_mm2, ‘b’);
title(‘Stress in Springs’);
xlabel(‘Time (s)’);
ylabel(‘Stress (N/mm²)’);
legend(‘Stress sigma_{kc}’, ‘Stress sigma_{ks}’, ‘Stress sigma_{kR}’);
grid on;
% Animation
figure;
% Define positions of masses and springs
y1_base = 2; % Base position of mass 1 (m)
y2_base = 1; % Base position of mass 2 (m)
y3_base = 0; % Base position of mass 3 (m)
% Plot settings
axis([-0.5 1.5 -1 30]);
hold on;
% Initial positions of masses
h_m1 = rectangle(‘Position’,[0.4 y1_base + y(1,1) 0.2 0.2], ‘Curvature’, [0.1 0.1], ‘FaceColor’, ‘blue’);
h_m2 = rectangle(‘Position’,[0.4 y2_base + y(1,2) 0.2 0.2], ‘Curvature’, [0.1 0.1], ‘FaceColor’, ‘green’);
h_m3 = rectangle(‘Position’,[0.4 y3_base + y(1,3) 0.2 0.2], ‘Curvature’, [0.1 0.1], ‘FaceColor’, ‘red’);
% Labels for masses
text(0.65, y1_base + y(1,1) + 0.1, ‘M_c’, ‘FontSize’, 12, ‘Color’, ‘blue’);
text(0.65, y2_base + y(1,2) + 0.1, ‘M_s’, ‘FontSize’, 12, ‘Color’, ‘green’);
text(0.65, y3_base + y(1,3) + 0.1, ‘M_{WL}’, ‘FontSize’, 12, ‘Color’, ‘red’);
% Initial positions of springs
h_spring1 = plot([0.5 0.5], [3 y1_base + y(1,1) + 0.2], ‘k’, ‘LineWidth’, 2);
h_spring2 = plot([0.5 0.5], [y1_base + y(1,1) y2_base + y(1,2) + 0.2], ‘k’, ‘LineWidth’, 2);
h_spring3 = plot([0.5 0.5], [y2_base + y(1,2) y3_base + y(1,3) + 0.2], ‘k’, ‘LineWidth’, 2);
% Labels for springs and dampers
text(0.3, 2.5, ‘k_c’, ‘FontSize’, 12, ‘Color’, ‘black’);
text(0.3, 1.5, ‘k_s’, ‘FontSize’, 12, ‘Color’, ‘black’);
text(0.3, 0.5, ‘k_R’, ‘FontSize’, 12, ‘Color’, ‘black’);
text(0.7, y1_base + (y2_base – y1_base) / 2 + y(1,1) / 2 + y(1,2) / 2, ‘c_s’, ‘FontSize’, 12, ‘Color’, ‘black’);
% Initial position of the damper
h_damper = plot([0.45 0.55], [y1_base + (y2_base – y1_base) / 2 + y(1,1) / 2 + y(1,2) / 2 y1_base + (y2_base – y1_base) / 2 + y(1,1) / 2 + y(1,2) / 2], ‘k’, ‘LineWidth’, 6);
% Animation loop
for i = 1:length(t)
% Update positions of masses
if isvalid(h_m1)
set(h_m1, ‘Position’, [0.4 y1_base + y(i,1) 0.2 0.2]);
end
if isvalid(h_m2)
set(h_m2, ‘Position’, [0.4 y2_base + y(i,2) 0.2 0.2]);
end
if isvalid(h_m3)
set(h_m3, ‘Position’, [0.4 y3_base + y(i,3) 0.2 0.2]);
end
% Update positions of springs
if isvalid(h_spring1)
set(h_spring1, ‘YData’, [3 y1_base + y(i,1) + 0.2]);
end
if isvalid(h_spring2)
set(h_spring2, ‘YData’, [y1_base + y(i,1) y2_base + y(i,2) + 0.2]);
end
if isvalid(h_spring3)
set(h_spring3, ‘YData’, [y2_base + y(i,2) y3_base + y(i,3) + 0.2]);
end
% Update position of the damper
if isvalid(h_damper)
set(h_damper, ‘YData’, [y1_base + (y2_base – y1_base) / 2 + y(i,1) / 2 + y(i,2) / 2 y1_base + (y2_base – y1_base) / 2 + y(i,1) / 2 + y(i,2) / 2]);
end
% Pause to create animation effect
pause(0.01);
end
hold off;
" Hello, I am designing the mass spring damper system in the image. I am creating this code for the design of a ship crane. In my road equation, there is an increase of approximately 20 meters, and the spring k_c is stretched by 20 meters. I just want the spring to follow the road, but the spring follows the road like an arrow, which is very high like 2000N/mm². Stress occurs. I think there is a mistake in my input equation, but I couldn’t figure it out completely. I would be very happy if you could help me
The image of the system is also attached.
Matlab code:
"% System parameters
M_c = 917; % Mass of the crane boom (kg)
M_s = 87; % Mass of the shock absorber (kg)
M_WL = 4075; % Mass of the working load (kg)
k_c = 554376; % Spring constant of the crane + crane hook ropes (N/m)
k_s = 24162; % Spring constant of the shock absorber system (N/m)
k_R = 9090572; % Spring constant of the lifting beam and lower rope (N/m)
c_s = 5800; % Damping constant of the shock absorber system (Ns/m)
A = 1.5; % Amplitude of input signal (m)
omega = 1; % Angular frequency of input signal (rad/s)
V_H1 = 0.69; % Linear term coefficient for first interval (m/s)
V_H2 = 0; % Linear term coefficient for second interval (m/s)
V_H3 = -0.1; % Linear term coefficient for third interval (m/s)
d_c = 0.026; % Diameter of spring kc (m)
d_s = 0.03; % Diameter of spring ks (m)
d_R = 0.0226; % Diameter of spring kR (m)
% Combined time vector with smaller sampling period
t = 0:0.01:45; % From 0 to 45 seconds with 0.01s sampling period
% Input signal (m)
u = zeros(size(t));
u(t <= 25) = A * sin(omega * t(t <= 25)) + V_H1 * t(t <= 25);
u(t > 25 & t <= 35) = A * sin(omega * t(t > 25 & t <= 35)) + V_H1 * 25 + V_H2 * (t(t > 25 & t <= 35) – 25);
u(t > 35) = A * sin(omega * t(t > 35)) + V_H1 * 25 + V_H3 * (t(t > 35) – 35);
% State-space matrix
A_matrix = [0 1 0 0 0 0;
-k_c/M_c -c_s/M_c k_s/M_c c_s/M_c 0 0;
0 0 0 1 0 0;
k_s/M_s c_s/M_s -(k_s+k_R)/M_s -c_s/M_s k_R/M_s 0;
0 0 0 0 0 1;
0 0 k_R/M_WL 0 -k_R/M_WL 0];
B_matrix = [0;
k_c/M_c;
0;
0;
0;
0];
C_matrix = [1 0 0 0 0 0;
0 0 1 0 0 0;
0 0 0 0 1 0];
D_matrix = [0;
0;
0];
% Create state-space model
sys = ss(A_matrix, B_matrix, C_matrix, D_matrix);
% Simulate system response
[y, t, x] = lsim(sys, u, t);
% Calculate spring extensions (m)
delta_kc = u’- y(:,1); % Extension of spring kc
delta_ks = y(:,1) – y(:,2); % Extension of spring ks
delta_kR = y(:,2) – y(:,3); % Extension of spring kR
% Convert spring extensions to meters (m)
delta_kc_m = delta_kc; % Assuming input signal u is in meters
delta_ks_m = delta_ks; % Assuming displacements are in meters
delta_kR_m = delta_kR; % Assuming displacements are in meters
% Calculate spring stresses (N/m²)
A_c = pi * (d_c/2)^2; % Cross-sectional area of spring kc (m²)
A_s = pi * (d_s/2)^2; % Cross-sectional area of spring ks (m²)
A_R = pi * (d_R/2)^2; % Cross-sectional area of spring kR (m²)
F_kc = k_c * delta_kc_m; % Force in spring kc (N)
F_ks = k_s * delta_ks_m; % Force in spring ks (N)
F_kR = k_R * delta_kR_m; % Force in spring kR (N)
sigma_kc = F_kc / A_c; % Stress in spring kc (N/m²)
sigma_ks = F_ks / A_s; % Stress in spring ks (N/m²)
sigma_kR = F_kR / A_R; % Stress in spring kR (N/m²)
% Convert stress to N/mm²
sigma_kc_mm2 = sigma_kc * 1e-6;
sigma_ks_mm2 = sigma_ks * 1e-6;
sigma_kR_mm2 = sigma_kR * 1e-6;
% Plot input signal and outputs
figure;
subplot(5,1,1);
plot(t, u);
title(‘Input Signal u’);
xlabel(‘Time (s)’);
ylabel(‘u (m)’);
subplot(5,1,2);
plot(t, y(:,1));
title(‘Output y1’);
xlabel(‘Time (s)’);
ylabel(‘y1 (m)’);
subplot(5,1,3);
plot(t, y(:,2));
title(‘Output y2’);
xlabel(‘Time (s)’);
ylabel(‘y2 (m)’);
subplot(5,1,4);
plot(t, y(:,3));
title(‘Output y3’);
xlabel(‘Time (s)’);
ylabel(‘y3 (m)’);
% Plot spring stresses in separate figures
subplot(5,1,5);
hold on;
plot(t, sigma_kc_mm2, ‘r’);
plot(t, sigma_ks_mm2, ‘g’);
plot(t, sigma_kR_mm2, ‘b’);
title(‘Stress in Springs’);
xlabel(‘Time (s)’);
ylabel(‘Stress (N/mm²)’);
legend(‘Stress sigma_{kc}’, ‘Stress sigma_{ks}’, ‘Stress sigma_{kR}’);
grid on;
% Animation
figure;
% Define positions of masses and springs
y1_base = 2; % Base position of mass 1 (m)
y2_base = 1; % Base position of mass 2 (m)
y3_base = 0; % Base position of mass 3 (m)
% Plot settings
axis([-0.5 1.5 -1 30]);
hold on;
% Initial positions of masses
h_m1 = rectangle(‘Position’,[0.4 y1_base + y(1,1) 0.2 0.2], ‘Curvature’, [0.1 0.1], ‘FaceColor’, ‘blue’);
h_m2 = rectangle(‘Position’,[0.4 y2_base + y(1,2) 0.2 0.2], ‘Curvature’, [0.1 0.1], ‘FaceColor’, ‘green’);
h_m3 = rectangle(‘Position’,[0.4 y3_base + y(1,3) 0.2 0.2], ‘Curvature’, [0.1 0.1], ‘FaceColor’, ‘red’);
% Labels for masses
text(0.65, y1_base + y(1,1) + 0.1, ‘M_c’, ‘FontSize’, 12, ‘Color’, ‘blue’);
text(0.65, y2_base + y(1,2) + 0.1, ‘M_s’, ‘FontSize’, 12, ‘Color’, ‘green’);
text(0.65, y3_base + y(1,3) + 0.1, ‘M_{WL}’, ‘FontSize’, 12, ‘Color’, ‘red’);
% Initial positions of springs
h_spring1 = plot([0.5 0.5], [3 y1_base + y(1,1) + 0.2], ‘k’, ‘LineWidth’, 2);
h_spring2 = plot([0.5 0.5], [y1_base + y(1,1) y2_base + y(1,2) + 0.2], ‘k’, ‘LineWidth’, 2);
h_spring3 = plot([0.5 0.5], [y2_base + y(1,2) y3_base + y(1,3) + 0.2], ‘k’, ‘LineWidth’, 2);
% Labels for springs and dampers
text(0.3, 2.5, ‘k_c’, ‘FontSize’, 12, ‘Color’, ‘black’);
text(0.3, 1.5, ‘k_s’, ‘FontSize’, 12, ‘Color’, ‘black’);
text(0.3, 0.5, ‘k_R’, ‘FontSize’, 12, ‘Color’, ‘black’);
text(0.7, y1_base + (y2_base – y1_base) / 2 + y(1,1) / 2 + y(1,2) / 2, ‘c_s’, ‘FontSize’, 12, ‘Color’, ‘black’);
% Initial position of the damper
h_damper = plot([0.45 0.55], [y1_base + (y2_base – y1_base) / 2 + y(1,1) / 2 + y(1,2) / 2 y1_base + (y2_base – y1_base) / 2 + y(1,1) / 2 + y(1,2) / 2], ‘k’, ‘LineWidth’, 6);
% Animation loop
for i = 1:length(t)
% Update positions of masses
if isvalid(h_m1)
set(h_m1, ‘Position’, [0.4 y1_base + y(i,1) 0.2 0.2]);
end
if isvalid(h_m2)
set(h_m2, ‘Position’, [0.4 y2_base + y(i,2) 0.2 0.2]);
end
if isvalid(h_m3)
set(h_m3, ‘Position’, [0.4 y3_base + y(i,3) 0.2 0.2]);
end
% Update positions of springs
if isvalid(h_spring1)
set(h_spring1, ‘YData’, [3 y1_base + y(i,1) + 0.2]);
end
if isvalid(h_spring2)
set(h_spring2, ‘YData’, [y1_base + y(i,1) y2_base + y(i,2) + 0.2]);
end
if isvalid(h_spring3)
set(h_spring3, ‘YData’, [y2_base + y(i,2) y3_base + y(i,3) + 0.2]);
end
% Update position of the damper
if isvalid(h_damper)
set(h_damper, ‘YData’, [y1_base + (y2_base – y1_base) / 2 + y(i,1) / 2 + y(i,2) / 2 y1_base + (y2_base – y1_base) / 2 + y(i,1) / 2 + y(i,2) / 2]);
end
% Pause to create animation effect
pause(0.01);
end
hold off;
" matlab code, mass spring damper, matlab MATLAB Answers — New Questions
Power operator (^) precedence levels and evaluation order
While
2^-1^-2
returns 4, which indicates a "left to right" evaluation order (as it is common in many programming languages),
2^-1^-2^3
returns 0.125, which I find surprising – I would have expected a value of 4^3 = 64.
To examine the order applied by Matlab, I tried all possible combinations:
((2^-1)^-2)^3 % returns 64 (1st, then 2nd operator)
(2^-1)^-(2^3) % returns 256 (1st and 3rd)
(2^-(1^-2))^3 % returns 0.125 (2nd, then 1st)
2^-((1^-2)^3) % returns 0.5 (2nd, then 3rd)
2^-(1^-(2^3)) % returns 0.5 (3rd, then 2nd)
So it seems that Matlab first evaluates the 2nd operator, then the 1st (=left), then the 3rd (=rightmost). That seems very odd. Can anybody explain why Matlab chooses this evaluation order?
I’m aware of https://de.mathworks.com/help/matlab/matlab_prog/operator-precedence.html, but it just doesn’t make sense to me. According to the rules given there, the 3rd operator (^) in my example should even come first, as it has a higher precedence than the other two (^-) operators. So doesn’t Matlab adhere to its own rules?While
2^-1^-2
returns 4, which indicates a "left to right" evaluation order (as it is common in many programming languages),
2^-1^-2^3
returns 0.125, which I find surprising – I would have expected a value of 4^3 = 64.
To examine the order applied by Matlab, I tried all possible combinations:
((2^-1)^-2)^3 % returns 64 (1st, then 2nd operator)
(2^-1)^-(2^3) % returns 256 (1st and 3rd)
(2^-(1^-2))^3 % returns 0.125 (2nd, then 1st)
2^-((1^-2)^3) % returns 0.5 (2nd, then 3rd)
2^-(1^-(2^3)) % returns 0.5 (3rd, then 2nd)
So it seems that Matlab first evaluates the 2nd operator, then the 1st (=left), then the 3rd (=rightmost). That seems very odd. Can anybody explain why Matlab chooses this evaluation order?
I’m aware of https://de.mathworks.com/help/matlab/matlab_prog/operator-precedence.html, but it just doesn’t make sense to me. According to the rules given there, the 3rd operator (^) in my example should even come first, as it has a higher precedence than the other two (^-) operators. So doesn’t Matlab adhere to its own rules? While
2^-1^-2
returns 4, which indicates a "left to right" evaluation order (as it is common in many programming languages),
2^-1^-2^3
returns 0.125, which I find surprising – I would have expected a value of 4^3 = 64.
To examine the order applied by Matlab, I tried all possible combinations:
((2^-1)^-2)^3 % returns 64 (1st, then 2nd operator)
(2^-1)^-(2^3) % returns 256 (1st and 3rd)
(2^-(1^-2))^3 % returns 0.125 (2nd, then 1st)
2^-((1^-2)^3) % returns 0.5 (2nd, then 3rd)
2^-(1^-(2^3)) % returns 0.5 (3rd, then 2nd)
So it seems that Matlab first evaluates the 2nd operator, then the 1st (=left), then the 3rd (=rightmost). That seems very odd. Can anybody explain why Matlab chooses this evaluation order?
I’m aware of https://de.mathworks.com/help/matlab/matlab_prog/operator-precedence.html, but it just doesn’t make sense to me. According to the rules given there, the 3rd operator (^) in my example should even come first, as it has a higher precedence than the other two (^-) operators. So doesn’t Matlab adhere to its own rules? power operator, precedence level, evaluation order, ^- MATLAB Answers — New Questions
How to interpolate 2-parameter dependents matrices?
So i have a set of matrixes F computed in different points (for each matrix there is associated a pair of points V,q). How do i compute an interpolation which gives me all possible F matrixes for values of (V,q) in a certain range not present in my dataset?
I wish i’ve been clear in my question, thank youSo i have a set of matrixes F computed in different points (for each matrix there is associated a pair of points V,q). How do i compute an interpolation which gives me all possible F matrixes for values of (V,q) in a certain range not present in my dataset?
I wish i’ve been clear in my question, thank you So i have a set of matrixes F computed in different points (for each matrix there is associated a pair of points V,q). How do i compute an interpolation which gives me all possible F matrixes for values of (V,q) in a certain range not present in my dataset?
I wish i’ve been clear in my question, thank you interpolation, lpv system, control engineering, gain scheduling MATLAB Answers — New Questions