Category: Matlab
Category Archives: Matlab
On import high dimensional data from csv, how to assign them appropriate optimal datatypes automatically?
I am working with a dataset that has 30,000 features most of them are logocal datatypes.
I wish that when this data is imported to workspace an appropriate optimal datatypes is assiged automatically to each column(attributes).
I observe through the data cleaning tool that they are not being assigned the optimal datatypes
such as logical datatypes are assigned double( wasting alot of space).
Manualy assigning will be very tedious task because of 30 thousand features.
Moreover, other algorithms are demanding too much memory because of this such as feature ranking methods and machine learning algorithms
Th system i am using has 32GB of RAM.I am working with a dataset that has 30,000 features most of them are logocal datatypes.
I wish that when this data is imported to workspace an appropriate optimal datatypes is assiged automatically to each column(attributes).
I observe through the data cleaning tool that they are not being assigned the optimal datatypes
such as logical datatypes are assigned double( wasting alot of space).
Manualy assigning will be very tedious task because of 30 thousand features.
Moreover, other algorithms are demanding too much memory because of this such as feature ranking methods and machine learning algorithms
Th system i am using has 32GB of RAM. I am working with a dataset that has 30,000 features most of them are logocal datatypes.
I wish that when this data is imported to workspace an appropriate optimal datatypes is assiged automatically to each column(attributes).
I observe through the data cleaning tool that they are not being assigned the optimal datatypes
such as logical datatypes are assigned double( wasting alot of space).
Manualy assigning will be very tedious task because of 30 thousand features.
Moreover, other algorithms are demanding too much memory because of this such as feature ranking methods and machine learning algorithms
Th system i am using has 32GB of RAM. high dimansional data, optimal datatypes casting, importing high dimensional data MATLAB Answers — New Questions
Hi, I am trying to get a curve fit to real data. and I have had a lot of problems. I am using the fminsearch function to get an estimate of the parameters; my questions are: 1
clear
close all
clc
% Données spécifiques
specific_data = [
2009 2 8;
2010 10 22;
2011 30 45;
2012 111 75;
2013 125 96;
2014 255 192;
2015 379 227;
2016 384 238
2017 360 279;
2018 399 229;
2019 235 128
];
% Utilisez les données spécifiques
tdata = specific_data(:, 1);
Hdata = specific_data(:, 2);
HSdata = specific_data(:, 3);
tforward = 2009:1:2019;
%tmeasure = [ 1:100:1001]’;
% initial values
gamma = 1.5;
phi_S = 0.0006; % transmission prob
phi_H = 0.000051; % trans proba
c1=3;
c2=1.5;
theta1 = 100; % djustment parameters for syph
theta2 = 4; %djustment parameters for hi
alpha = 0.6; % progression rate
beta = 0.2; %Complications rate
rho1 = 0.4; % adjustment parameters
rho2 = 1.5; % adjustment parameters
rho3 = 1.5; % adjustment parameters
k0 = [phi_S phi_H c1 c2 theta1 theta2 alpha beta rho1 rho2 rho3 ];
% solve equ with initial value of parameters
[t, Y] = ode23s(@(t, y)modelhs(t, y, k0), tforward, [ 5000.0 20.0 2.0 0.0 6.0 2.0 0.0 ]);
yintM = Y(:,1);
yintS = Y(:,2);
yintH1 = Y(:,3);
yintH2 = Y(:,4);
yintH1S=Y(:,5);
yintH2S=Y(:,6);
Hh=phi_H * ( yintH1 + c1 * yintH1S ).*yintM + rho1 * gamma * yintH1S + alpha* yintH2; % new cases from monoH
HShs=theta1*phi_S * ( yintS + c2 * yintH1S ).*yintH1 + theta2*phi_H * ( yintH1 + c1 * yintH1S ).*yintS+ rho2*alpha*yintH1S; %new case of co h-s
%H2q = Y(:,4);% assignts the y-coordinates of .
% Plotting specific data and solutions
% Display the results
figure(1)
%subplot(1,2,1);
plot(tdata, Hdata, ‘r*’);
hold on
plot(tdata, Hh, ‘b-‘);
xlabel(‘time in days’);
ylabel(‘Number of monhiv cases’);
axis([2009 2019 0 500]);
figure(2)
%subplot(1,2,1);
plot(tdata, HSdata, ‘r*’);
hold on
plot(tdata, HShs, ‘b-‘);
xlabel(‘time in days’);
ylabel(‘Number of Coinfection cases’);
axis([2009 2019 0 500]);
% Minimization routine using Nelder & Mead Simplex algorithm (a derivative-free method)
% Assigns the new values of parameters to k and the error to fval
% Minimization routine using Nelder & Mead Simplex algorithm (a derivative-free method)
% Assigns the new values of parameters to k and the error to fval
[k,fval] = fminsearch(@moderHS,k0)
%print final values of alpha and beta
disp(k);
%Draw the data with the final ODE
[T, Y] = ode45(@(t,y)(modelhs(t,y,k)),tforward,[ 5000.0 20.0 2.0 0.0 6.0 2.0 0.0 ]);
yintM = Y(:,1);
yintS = Y(:,2);
yintH1 = Y(:,3);
yintH2 = Y(:,4);
yintH1S=Y(:,5);
yintH2S=Y(:,6);
Hh=phi_H * ( yintH1 + c1 * yintH1S ).*yintM + rho1 * gamma * yintH1S + alpha* yintH2; % new cases from mono-HIV
HShs=theta1*phi_S * ( yintS + c2 * yintH1S ).*yintH1 + theta2*phi_H * ( yintH1 + c1 * yintH1S ).*yintS+ rho2*alpha*yintH1S; %new case of coinfection hiv+syphilis
%H2q = Y(:,4);% assignts the y-coordinates of …
residuals = (Hdata+HSdata – Hh-HShs)./2;
%subplot(1,2,2);
figure(3)
plot(tdata,Hdata,’r*’);
hold on
plot(tdata,Hh,’b-‘);
xlabel(‘Time in days’);
ylabel(‘Number of mono-HIV cases’);
axis([2009 2019 0 1000]);
legend(‘Data’, ‘Model estimation’);
figure(4)
plot(tdata,HSdata,’r*’);
hold on
plot(tdata,HShs,’b-‘);
xlabel(‘Time in days’);
ylabel(‘Number of Coinfection cases’);
axis([2009 2019 0 1000]);
legend(‘Data’, ‘Model estimation’);
function dy=modelhs(~,y,k)
delta = 0.01; % Taux de mortalité
delta_S = 0.05; % Taux de mort de Syphilis.
delta_H = 0.4;
Lambda =4.04 *100;
gamma=1.5;
phi_S =k(1);
phi_H =k(2);
c1 = k(3);
c2=k(4) ;
theta1 =k(5) ;
theta2 = k(6);
alpha = k(7);
beta = k(8);
rho1 = k(9);
rho2= k(10);
rho3=k(11);
dy = zeros(7,1);
%lambda_s=phi_S * ( y(2) + c2 * y(5))
%lambda_H= phi_H * ( y(3) + c1 * y(5) )
dy(1) = Lambda + gamma * y(2) – (phi_S * ( y(2) + c2 * y(5)) + phi_H * (y(3) + c1 * y(5)) + delta ) * y(1) ;%M
dy(2)= phi_S * ( y(2) + c2 * y(5) ) * y(1) – ( gamma + theta2 * phi_H * ( y(3) + c1 * y(5) ) + delta_S ) * y(2) ;%S
dy(3) = phi_H * ( y(3) + c1 * y(5) ) * y(1) + rho1 * gamma * y(5) – (theta1 * phi_S * ( y(2) + c2 * y(5)) + delta + delta_H + alpha) * y(3) ;%H1
dy(4) = alpha * y(3) – (beta + delta + delta_H) * y(4) ;%H2
dy(5) = theta2 * phi_H * ( y(3) + c1 * y(5) ) * y(2) + ( theta1 * phi_S * ( y(2) + c2 * y(5) ) ) * y(3) – ( rho1 * gamma + rho2 * alpha + delta_H + delta_S + delta ) * y(5) ;%H1S
dy(6)= rho2 * alpha * y(5) – ( rho3 * beta + delta_S + delta_H + delta ) * y(6) ;%H2S
dy(7)= beta * y(4) + rho3 * beta * y(6) – ( delta + delta_H ) * y(7) ;%C
end
function error_in_data = moderHS(k)
% Données spécifiques
specific_data = [
2009 2 8;
2010 10 22;
2011 30 45;
2012 111 75;
2013 125 96;
2014 255 192;
2015 379 227;
2016 384 238
2017 360 279;
2018 399 229;
2019 235 128
];
gamma = 1.5;
phi_S =k(1);
phi_H =k(2);
c1 = k(3);
c2=k(4) ;
theta1 =k(5) ;
theta2 = k(6);
alpha = k(7);
beta = k(8);
rho1 = k(9);
rho2= k(10);
rho3=k(11);
% Utilisez les données spécifiques
tdata = specific_data(:, 1);
Hdata = specific_data(:, 2);
HSdata = specific_data(:, 3);
tforward = 2009:1:2019;
[T, Y] = ode23s(@(t,y)(modelhs(t,y,k)),tforward,[ 5000.0 20.0 2.0 0.0 6.0 2.0 0.0 ]);
M = Y(:,1);
S = Y(:,2);
H1 = Y(:,3);
H2 = Y(:,4);
H1S=Y(:,5);
H2S=Y(:,6);
H=phi_H * ( H1 + c1 * H1S ).*M + rho1 * gamma*H1S + alpha* H2; % new cases from mono-HIV
HS=theta1*phi_S * ( S + c2 * H1S ).*H1 + theta2*phi_H * ( H1 + c1 * H1S ).*S+ rho2*alpha*H1S; %new case of coinfection hiv+syphilis
%H2q = Y(:,4);% assignts the y-coordinates of …
%the solution at
D=mean(Hdata).^2;
D1=mean(HSdata).^2;
A=(H – Hdata).^2;
B=(HS – HSdata).^2;
error_in_data =sum(A)./(11*D)+ sum(B)./(11*D1);
%%
endclear
close all
clc
% Données spécifiques
specific_data = [
2009 2 8;
2010 10 22;
2011 30 45;
2012 111 75;
2013 125 96;
2014 255 192;
2015 379 227;
2016 384 238
2017 360 279;
2018 399 229;
2019 235 128
];
% Utilisez les données spécifiques
tdata = specific_data(:, 1);
Hdata = specific_data(:, 2);
HSdata = specific_data(:, 3);
tforward = 2009:1:2019;
%tmeasure = [ 1:100:1001]’;
% initial values
gamma = 1.5;
phi_S = 0.0006; % transmission prob
phi_H = 0.000051; % trans proba
c1=3;
c2=1.5;
theta1 = 100; % djustment parameters for syph
theta2 = 4; %djustment parameters for hi
alpha = 0.6; % progression rate
beta = 0.2; %Complications rate
rho1 = 0.4; % adjustment parameters
rho2 = 1.5; % adjustment parameters
rho3 = 1.5; % adjustment parameters
k0 = [phi_S phi_H c1 c2 theta1 theta2 alpha beta rho1 rho2 rho3 ];
% solve equ with initial value of parameters
[t, Y] = ode23s(@(t, y)modelhs(t, y, k0), tforward, [ 5000.0 20.0 2.0 0.0 6.0 2.0 0.0 ]);
yintM = Y(:,1);
yintS = Y(:,2);
yintH1 = Y(:,3);
yintH2 = Y(:,4);
yintH1S=Y(:,5);
yintH2S=Y(:,6);
Hh=phi_H * ( yintH1 + c1 * yintH1S ).*yintM + rho1 * gamma * yintH1S + alpha* yintH2; % new cases from monoH
HShs=theta1*phi_S * ( yintS + c2 * yintH1S ).*yintH1 + theta2*phi_H * ( yintH1 + c1 * yintH1S ).*yintS+ rho2*alpha*yintH1S; %new case of co h-s
%H2q = Y(:,4);% assignts the y-coordinates of .
% Plotting specific data and solutions
% Display the results
figure(1)
%subplot(1,2,1);
plot(tdata, Hdata, ‘r*’);
hold on
plot(tdata, Hh, ‘b-‘);
xlabel(‘time in days’);
ylabel(‘Number of monhiv cases’);
axis([2009 2019 0 500]);
figure(2)
%subplot(1,2,1);
plot(tdata, HSdata, ‘r*’);
hold on
plot(tdata, HShs, ‘b-‘);
xlabel(‘time in days’);
ylabel(‘Number of Coinfection cases’);
axis([2009 2019 0 500]);
% Minimization routine using Nelder & Mead Simplex algorithm (a derivative-free method)
% Assigns the new values of parameters to k and the error to fval
% Minimization routine using Nelder & Mead Simplex algorithm (a derivative-free method)
% Assigns the new values of parameters to k and the error to fval
[k,fval] = fminsearch(@moderHS,k0)
%print final values of alpha and beta
disp(k);
%Draw the data with the final ODE
[T, Y] = ode45(@(t,y)(modelhs(t,y,k)),tforward,[ 5000.0 20.0 2.0 0.0 6.0 2.0 0.0 ]);
yintM = Y(:,1);
yintS = Y(:,2);
yintH1 = Y(:,3);
yintH2 = Y(:,4);
yintH1S=Y(:,5);
yintH2S=Y(:,6);
Hh=phi_H * ( yintH1 + c1 * yintH1S ).*yintM + rho1 * gamma * yintH1S + alpha* yintH2; % new cases from mono-HIV
HShs=theta1*phi_S * ( yintS + c2 * yintH1S ).*yintH1 + theta2*phi_H * ( yintH1 + c1 * yintH1S ).*yintS+ rho2*alpha*yintH1S; %new case of coinfection hiv+syphilis
%H2q = Y(:,4);% assignts the y-coordinates of …
residuals = (Hdata+HSdata – Hh-HShs)./2;
%subplot(1,2,2);
figure(3)
plot(tdata,Hdata,’r*’);
hold on
plot(tdata,Hh,’b-‘);
xlabel(‘Time in days’);
ylabel(‘Number of mono-HIV cases’);
axis([2009 2019 0 1000]);
legend(‘Data’, ‘Model estimation’);
figure(4)
plot(tdata,HSdata,’r*’);
hold on
plot(tdata,HShs,’b-‘);
xlabel(‘Time in days’);
ylabel(‘Number of Coinfection cases’);
axis([2009 2019 0 1000]);
legend(‘Data’, ‘Model estimation’);
function dy=modelhs(~,y,k)
delta = 0.01; % Taux de mortalité
delta_S = 0.05; % Taux de mort de Syphilis.
delta_H = 0.4;
Lambda =4.04 *100;
gamma=1.5;
phi_S =k(1);
phi_H =k(2);
c1 = k(3);
c2=k(4) ;
theta1 =k(5) ;
theta2 = k(6);
alpha = k(7);
beta = k(8);
rho1 = k(9);
rho2= k(10);
rho3=k(11);
dy = zeros(7,1);
%lambda_s=phi_S * ( y(2) + c2 * y(5))
%lambda_H= phi_H * ( y(3) + c1 * y(5) )
dy(1) = Lambda + gamma * y(2) – (phi_S * ( y(2) + c2 * y(5)) + phi_H * (y(3) + c1 * y(5)) + delta ) * y(1) ;%M
dy(2)= phi_S * ( y(2) + c2 * y(5) ) * y(1) – ( gamma + theta2 * phi_H * ( y(3) + c1 * y(5) ) + delta_S ) * y(2) ;%S
dy(3) = phi_H * ( y(3) + c1 * y(5) ) * y(1) + rho1 * gamma * y(5) – (theta1 * phi_S * ( y(2) + c2 * y(5)) + delta + delta_H + alpha) * y(3) ;%H1
dy(4) = alpha * y(3) – (beta + delta + delta_H) * y(4) ;%H2
dy(5) = theta2 * phi_H * ( y(3) + c1 * y(5) ) * y(2) + ( theta1 * phi_S * ( y(2) + c2 * y(5) ) ) * y(3) – ( rho1 * gamma + rho2 * alpha + delta_H + delta_S + delta ) * y(5) ;%H1S
dy(6)= rho2 * alpha * y(5) – ( rho3 * beta + delta_S + delta_H + delta ) * y(6) ;%H2S
dy(7)= beta * y(4) + rho3 * beta * y(6) – ( delta + delta_H ) * y(7) ;%C
end
function error_in_data = moderHS(k)
% Données spécifiques
specific_data = [
2009 2 8;
2010 10 22;
2011 30 45;
2012 111 75;
2013 125 96;
2014 255 192;
2015 379 227;
2016 384 238
2017 360 279;
2018 399 229;
2019 235 128
];
gamma = 1.5;
phi_S =k(1);
phi_H =k(2);
c1 = k(3);
c2=k(4) ;
theta1 =k(5) ;
theta2 = k(6);
alpha = k(7);
beta = k(8);
rho1 = k(9);
rho2= k(10);
rho3=k(11);
% Utilisez les données spécifiques
tdata = specific_data(:, 1);
Hdata = specific_data(:, 2);
HSdata = specific_data(:, 3);
tforward = 2009:1:2019;
[T, Y] = ode23s(@(t,y)(modelhs(t,y,k)),tforward,[ 5000.0 20.0 2.0 0.0 6.0 2.0 0.0 ]);
M = Y(:,1);
S = Y(:,2);
H1 = Y(:,3);
H2 = Y(:,4);
H1S=Y(:,5);
H2S=Y(:,6);
H=phi_H * ( H1 + c1 * H1S ).*M + rho1 * gamma*H1S + alpha* H2; % new cases from mono-HIV
HS=theta1*phi_S * ( S + c2 * H1S ).*H1 + theta2*phi_H * ( H1 + c1 * H1S ).*S+ rho2*alpha*H1S; %new case of coinfection hiv+syphilis
%H2q = Y(:,4);% assignts the y-coordinates of …
%the solution at
D=mean(Hdata).^2;
D1=mean(HSdata).^2;
A=(H – Hdata).^2;
B=(HS – HSdata).^2;
error_in_data =sum(A)./(11*D)+ sum(B)./(11*D1);
%%
end clear
close all
clc
% Données spécifiques
specific_data = [
2009 2 8;
2010 10 22;
2011 30 45;
2012 111 75;
2013 125 96;
2014 255 192;
2015 379 227;
2016 384 238
2017 360 279;
2018 399 229;
2019 235 128
];
% Utilisez les données spécifiques
tdata = specific_data(:, 1);
Hdata = specific_data(:, 2);
HSdata = specific_data(:, 3);
tforward = 2009:1:2019;
%tmeasure = [ 1:100:1001]’;
% initial values
gamma = 1.5;
phi_S = 0.0006; % transmission prob
phi_H = 0.000051; % trans proba
c1=3;
c2=1.5;
theta1 = 100; % djustment parameters for syph
theta2 = 4; %djustment parameters for hi
alpha = 0.6; % progression rate
beta = 0.2; %Complications rate
rho1 = 0.4; % adjustment parameters
rho2 = 1.5; % adjustment parameters
rho3 = 1.5; % adjustment parameters
k0 = [phi_S phi_H c1 c2 theta1 theta2 alpha beta rho1 rho2 rho3 ];
% solve equ with initial value of parameters
[t, Y] = ode23s(@(t, y)modelhs(t, y, k0), tforward, [ 5000.0 20.0 2.0 0.0 6.0 2.0 0.0 ]);
yintM = Y(:,1);
yintS = Y(:,2);
yintH1 = Y(:,3);
yintH2 = Y(:,4);
yintH1S=Y(:,5);
yintH2S=Y(:,6);
Hh=phi_H * ( yintH1 + c1 * yintH1S ).*yintM + rho1 * gamma * yintH1S + alpha* yintH2; % new cases from monoH
HShs=theta1*phi_S * ( yintS + c2 * yintH1S ).*yintH1 + theta2*phi_H * ( yintH1 + c1 * yintH1S ).*yintS+ rho2*alpha*yintH1S; %new case of co h-s
%H2q = Y(:,4);% assignts the y-coordinates of .
% Plotting specific data and solutions
% Display the results
figure(1)
%subplot(1,2,1);
plot(tdata, Hdata, ‘r*’);
hold on
plot(tdata, Hh, ‘b-‘);
xlabel(‘time in days’);
ylabel(‘Number of monhiv cases’);
axis([2009 2019 0 500]);
figure(2)
%subplot(1,2,1);
plot(tdata, HSdata, ‘r*’);
hold on
plot(tdata, HShs, ‘b-‘);
xlabel(‘time in days’);
ylabel(‘Number of Coinfection cases’);
axis([2009 2019 0 500]);
% Minimization routine using Nelder & Mead Simplex algorithm (a derivative-free method)
% Assigns the new values of parameters to k and the error to fval
% Minimization routine using Nelder & Mead Simplex algorithm (a derivative-free method)
% Assigns the new values of parameters to k and the error to fval
[k,fval] = fminsearch(@moderHS,k0)
%print final values of alpha and beta
disp(k);
%Draw the data with the final ODE
[T, Y] = ode45(@(t,y)(modelhs(t,y,k)),tforward,[ 5000.0 20.0 2.0 0.0 6.0 2.0 0.0 ]);
yintM = Y(:,1);
yintS = Y(:,2);
yintH1 = Y(:,3);
yintH2 = Y(:,4);
yintH1S=Y(:,5);
yintH2S=Y(:,6);
Hh=phi_H * ( yintH1 + c1 * yintH1S ).*yintM + rho1 * gamma * yintH1S + alpha* yintH2; % new cases from mono-HIV
HShs=theta1*phi_S * ( yintS + c2 * yintH1S ).*yintH1 + theta2*phi_H * ( yintH1 + c1 * yintH1S ).*yintS+ rho2*alpha*yintH1S; %new case of coinfection hiv+syphilis
%H2q = Y(:,4);% assignts the y-coordinates of …
residuals = (Hdata+HSdata – Hh-HShs)./2;
%subplot(1,2,2);
figure(3)
plot(tdata,Hdata,’r*’);
hold on
plot(tdata,Hh,’b-‘);
xlabel(‘Time in days’);
ylabel(‘Number of mono-HIV cases’);
axis([2009 2019 0 1000]);
legend(‘Data’, ‘Model estimation’);
figure(4)
plot(tdata,HSdata,’r*’);
hold on
plot(tdata,HShs,’b-‘);
xlabel(‘Time in days’);
ylabel(‘Number of Coinfection cases’);
axis([2009 2019 0 1000]);
legend(‘Data’, ‘Model estimation’);
function dy=modelhs(~,y,k)
delta = 0.01; % Taux de mortalité
delta_S = 0.05; % Taux de mort de Syphilis.
delta_H = 0.4;
Lambda =4.04 *100;
gamma=1.5;
phi_S =k(1);
phi_H =k(2);
c1 = k(3);
c2=k(4) ;
theta1 =k(5) ;
theta2 = k(6);
alpha = k(7);
beta = k(8);
rho1 = k(9);
rho2= k(10);
rho3=k(11);
dy = zeros(7,1);
%lambda_s=phi_S * ( y(2) + c2 * y(5))
%lambda_H= phi_H * ( y(3) + c1 * y(5) )
dy(1) = Lambda + gamma * y(2) – (phi_S * ( y(2) + c2 * y(5)) + phi_H * (y(3) + c1 * y(5)) + delta ) * y(1) ;%M
dy(2)= phi_S * ( y(2) + c2 * y(5) ) * y(1) – ( gamma + theta2 * phi_H * ( y(3) + c1 * y(5) ) + delta_S ) * y(2) ;%S
dy(3) = phi_H * ( y(3) + c1 * y(5) ) * y(1) + rho1 * gamma * y(5) – (theta1 * phi_S * ( y(2) + c2 * y(5)) + delta + delta_H + alpha) * y(3) ;%H1
dy(4) = alpha * y(3) – (beta + delta + delta_H) * y(4) ;%H2
dy(5) = theta2 * phi_H * ( y(3) + c1 * y(5) ) * y(2) + ( theta1 * phi_S * ( y(2) + c2 * y(5) ) ) * y(3) – ( rho1 * gamma + rho2 * alpha + delta_H + delta_S + delta ) * y(5) ;%H1S
dy(6)= rho2 * alpha * y(5) – ( rho3 * beta + delta_S + delta_H + delta ) * y(6) ;%H2S
dy(7)= beta * y(4) + rho3 * beta * y(6) – ( delta + delta_H ) * y(7) ;%C
end
function error_in_data = moderHS(k)
% Données spécifiques
specific_data = [
2009 2 8;
2010 10 22;
2011 30 45;
2012 111 75;
2013 125 96;
2014 255 192;
2015 379 227;
2016 384 238
2017 360 279;
2018 399 229;
2019 235 128
];
gamma = 1.5;
phi_S =k(1);
phi_H =k(2);
c1 = k(3);
c2=k(4) ;
theta1 =k(5) ;
theta2 = k(6);
alpha = k(7);
beta = k(8);
rho1 = k(9);
rho2= k(10);
rho3=k(11);
% Utilisez les données spécifiques
tdata = specific_data(:, 1);
Hdata = specific_data(:, 2);
HSdata = specific_data(:, 3);
tforward = 2009:1:2019;
[T, Y] = ode23s(@(t,y)(modelhs(t,y,k)),tforward,[ 5000.0 20.0 2.0 0.0 6.0 2.0 0.0 ]);
M = Y(:,1);
S = Y(:,2);
H1 = Y(:,3);
H2 = Y(:,4);
H1S=Y(:,5);
H2S=Y(:,6);
H=phi_H * ( H1 + c1 * H1S ).*M + rho1 * gamma*H1S + alpha* H2; % new cases from mono-HIV
HS=theta1*phi_S * ( S + c2 * H1S ).*H1 + theta2*phi_H * ( H1 + c1 * H1S ).*S+ rho2*alpha*H1S; %new case of coinfection hiv+syphilis
%H2q = Y(:,4);% assignts the y-coordinates of …
%the solution at
D=mean(Hdata).^2;
D1=mean(HSdata).^2;
A=(H – Hdata).^2;
B=(HS – HSdata).^2;
error_in_data =sum(A)./(11*D)+ sum(B)./(11*D1);
%%
end fiting, code, estimation of parameters, optimization MATLAB Answers — New Questions
I’m using VIT transformer in my code. How to convert the output of 1D layer of VIT into 2D with format SSCB?
I used the following code from Matlab answer to solve the errorrs that shown in the attached figure.
(Samuel Somuyiwa on 24 Jul 2023)
% Get Vision Transformer model
net = visionTransformer;
% Create dummy input
input = dlarray(rand(384,384,3),’SSCB’);
% Obtain output embedding from last layerNormalizationLayer
out = forward(net, input, Outputs=’encoder_norm’);
% Reshape output patch embedding
out = reshapePatchEmbedding(out);
function out = reshapePatchEmbedding(in)
% Remove output embedding corresponding to class token from input
out = in(2:end,:,:);
% Reshape resulting embedding to input format
WH = sqrt(size(out, 1));
C = size(out, 2);
out = reshape(out, WH, WH, C, []); % Shape is W x H x C x N
out = permute(out, [2, 1, 3, 4]); % Shape is H x W x C x N
% Convert to formatted dlarray
out = dlarray(out, ‘SSCB’);
endI used the following code from Matlab answer to solve the errorrs that shown in the attached figure.
(Samuel Somuyiwa on 24 Jul 2023)
% Get Vision Transformer model
net = visionTransformer;
% Create dummy input
input = dlarray(rand(384,384,3),’SSCB’);
% Obtain output embedding from last layerNormalizationLayer
out = forward(net, input, Outputs=’encoder_norm’);
% Reshape output patch embedding
out = reshapePatchEmbedding(out);
function out = reshapePatchEmbedding(in)
% Remove output embedding corresponding to class token from input
out = in(2:end,:,:);
% Reshape resulting embedding to input format
WH = sqrt(size(out, 1));
C = size(out, 2);
out = reshape(out, WH, WH, C, []); % Shape is W x H x C x N
out = permute(out, [2, 1, 3, 4]); % Shape is H x W x C x N
% Convert to formatted dlarray
out = dlarray(out, ‘SSCB’);
end I used the following code from Matlab answer to solve the errorrs that shown in the attached figure.
(Samuel Somuyiwa on 24 Jul 2023)
% Get Vision Transformer model
net = visionTransformer;
% Create dummy input
input = dlarray(rand(384,384,3),’SSCB’);
% Obtain output embedding from last layerNormalizationLayer
out = forward(net, input, Outputs=’encoder_norm’);
% Reshape output patch embedding
out = reshapePatchEmbedding(out);
function out = reshapePatchEmbedding(in)
% Remove output embedding corresponding to class token from input
out = in(2:end,:,:);
% Reshape resulting embedding to input format
WH = sqrt(size(out, 1));
C = size(out, 2);
out = reshape(out, WH, WH, C, []); % Shape is W x H x C x N
out = permute(out, [2, 1, 3, 4]); % Shape is H x W x C x N
% Convert to formatted dlarray
out = dlarray(out, ‘SSCB’);
end deep learning MATLAB Answers — New Questions
I want to use the multicore function of Simulink to accelarate my simulation. Having errors when profiling. It can not find the header file?
This the error shown in matlab command windows. I don’t konw how to solve this!
cpp: e:multicoretestnewmaintest grt rtwrt main.c:22 Could not find include file <processthreadsapi.h>
Error rt main.c: 287 operands of= have illegal types ‘pointer to void’ and ‘int’
Error rt main.c: 360 operands of= have illegal types ‘pointer to void’ and ‘int’
2 errors, 1 warning
The line 287 and Line 360 of rt_main.c is
orTimer = CreateWaitableTimer((NULL), false, (NULL));This the error shown in matlab command windows. I don’t konw how to solve this!
cpp: e:multicoretestnewmaintest grt rtwrt main.c:22 Could not find include file <processthreadsapi.h>
Error rt main.c: 287 operands of= have illegal types ‘pointer to void’ and ‘int’
Error rt main.c: 360 operands of= have illegal types ‘pointer to void’ and ‘int’
2 errors, 1 warning
The line 287 and Line 360 of rt_main.c is
orTimer = CreateWaitableTimer((NULL), false, (NULL)); This the error shown in matlab command windows. I don’t konw how to solve this!
cpp: e:multicoretestnewmaintest grt rtwrt main.c:22 Could not find include file <processthreadsapi.h>
Error rt main.c: 287 operands of= have illegal types ‘pointer to void’ and ‘int’
Error rt main.c: 360 operands of= have illegal types ‘pointer to void’ and ‘int’
2 errors, 1 warning
The line 287 and Line 360 of rt_main.c is
orTimer = CreateWaitableTimer((NULL), false, (NULL)); multicore, concurrent execution MATLAB Answers — New Questions
plotting multiple boxplots in the same figure window
I have 10 vectors of temperature data, all different lengths, that I want to make boxplots of and plot them all in the same figure window. How do I do this?I have 10 vectors of temperature data, all different lengths, that I want to make boxplots of and plot them all in the same figure window. How do I do this? I have 10 vectors of temperature data, all different lengths, that I want to make boxplots of and plot them all in the same figure window. How do I do this? boxplots, multiple vectors MATLAB Answers — New Questions
maximum clique problem solve
Maximum Clique
People in the social network are identified by unique IDs, consecutive integers from 1 to N. Who follows who is captured in a cell array called sn: the ii th element of sn is a vector that contains a list of IDs the person with ID ii follows. You may assume that these lists are ordered in ascending order by ID. Note that the follows relationship is not necessarily symmetrical: if person A follows person B, person B may or may not follow person A. :
function clique = max_clique(graph, clique)
if nargin < 2
clique = [];
end
max_clq = clique;
if isempty(clique)
for ii= 1:length(graph)
clq = max_clique(graph,ii);
if length(clq) > length(max_clq)
max_clq = clq;
end
end
else
for node=1:length(graph)
if isempty(find(node==clique))
if check_clique(clique,node,graph)
clq = max_clique(graph, [clique node]);
if length(clq) > length(max_clq)
max_clique == clq
end
end
end
end
end
clique = max_clq;
end
function ok = check_clique(clq,node,graph)
ok = false;
for ii=1:length(clq)
if isempty(find(clq(ii) == graph{node})) || isempty (find(node == graph{clq(ii)}))
return;
end
end
ok = true;
end
Unfortunately, it is too slow and the grader will time out. Your task is to modify the code to speed it up. Remember, the question to ask: am I doing any unncessary work? Call the modified function max_clique. (Hint: when we try to expand the current clique, do we really need to consider all the nodes?)
Please solve this problem with entire new code that is fast.Maximum Clique
People in the social network are identified by unique IDs, consecutive integers from 1 to N. Who follows who is captured in a cell array called sn: the ii th element of sn is a vector that contains a list of IDs the person with ID ii follows. You may assume that these lists are ordered in ascending order by ID. Note that the follows relationship is not necessarily symmetrical: if person A follows person B, person B may or may not follow person A. :
function clique = max_clique(graph, clique)
if nargin < 2
clique = [];
end
max_clq = clique;
if isempty(clique)
for ii= 1:length(graph)
clq = max_clique(graph,ii);
if length(clq) > length(max_clq)
max_clq = clq;
end
end
else
for node=1:length(graph)
if isempty(find(node==clique))
if check_clique(clique,node,graph)
clq = max_clique(graph, [clique node]);
if length(clq) > length(max_clq)
max_clique == clq
end
end
end
end
end
clique = max_clq;
end
function ok = check_clique(clq,node,graph)
ok = false;
for ii=1:length(clq)
if isempty(find(clq(ii) == graph{node})) || isempty (find(node == graph{clq(ii)}))
return;
end
end
ok = true;
end
Unfortunately, it is too slow and the grader will time out. Your task is to modify the code to speed it up. Remember, the question to ask: am I doing any unncessary work? Call the modified function max_clique. (Hint: when we try to expand the current clique, do we really need to consider all the nodes?)
Please solve this problem with entire new code that is fast. Maximum Clique
People in the social network are identified by unique IDs, consecutive integers from 1 to N. Who follows who is captured in a cell array called sn: the ii th element of sn is a vector that contains a list of IDs the person with ID ii follows. You may assume that these lists are ordered in ascending order by ID. Note that the follows relationship is not necessarily symmetrical: if person A follows person B, person B may or may not follow person A. :
function clique = max_clique(graph, clique)
if nargin < 2
clique = [];
end
max_clq = clique;
if isempty(clique)
for ii= 1:length(graph)
clq = max_clique(graph,ii);
if length(clq) > length(max_clq)
max_clq = clq;
end
end
else
for node=1:length(graph)
if isempty(find(node==clique))
if check_clique(clique,node,graph)
clq = max_clique(graph, [clique node]);
if length(clq) > length(max_clq)
max_clique == clq
end
end
end
end
end
clique = max_clq;
end
function ok = check_clique(clq,node,graph)
ok = false;
for ii=1:length(clq)
if isempty(find(clq(ii) == graph{node})) || isempty (find(node == graph{clq(ii)}))
return;
end
end
ok = true;
end
Unfortunately, it is too slow and the grader will time out. Your task is to modify the code to speed it up. Remember, the question to ask: am I doing any unncessary work? Call the modified function max_clique. (Hint: when we try to expand the current clique, do we really need to consider all the nodes?)
Please solve this problem with entire new code that is fast. maximum_clique MATLAB Answers — New Questions
Profiling of inefficient recursive Fibonacci series function
I am asked to profile an intentionally inefficient code. Following code will overtime with a huge input:
function f = fibo(n)
if n <= 2
f = 1;
else
f = fibo(n-2) + fibo(n-1);
end
end
I used a persistente variable, to create an array that reflects the recursion calls:
function [f, trace]=fibo_trace(n,v)%with persistent variable ‘trc’
persistent trc;
if isempty(trc)
trc=v;
end
if n<=2
trc=[trc n];
f=1;
else
trc=[trc n];
f=fibo_trace(n-2)+fibo_trace(n-1);
end
trace=trc;
end
That works flawlessly when I run the function with followin code:
[f trace] = fibo_trace(6,[])
And this is what the code returns:
f = 8
trace = 6 4 2 3 1 2 5 3 1 2 4 2 3 1 2,
which is OK, since the trace vector shows how inefficient the original code is. Now my problem is, it is an assigment for a MOOC platform and the solution with the persistent variable won’t work because the the automated grader will run the function a number of times with random inputs and it will not clear the function. Without the persistent variable I must split the recursive calls in two code lines and I am struggling now to compute the nth fibonacci number:
Can anyone give a clue? The creation of the array works but I honestly don’t know how to deal with the two recursive call lines to compute the fibonacci.I am asked to profile an intentionally inefficient code. Following code will overtime with a huge input:
function f = fibo(n)
if n <= 2
f = 1;
else
f = fibo(n-2) + fibo(n-1);
end
end
I used a persistente variable, to create an array that reflects the recursion calls:
function [f, trace]=fibo_trace(n,v)%with persistent variable ‘trc’
persistent trc;
if isempty(trc)
trc=v;
end
if n<=2
trc=[trc n];
f=1;
else
trc=[trc n];
f=fibo_trace(n-2)+fibo_trace(n-1);
end
trace=trc;
end
That works flawlessly when I run the function with followin code:
[f trace] = fibo_trace(6,[])
And this is what the code returns:
f = 8
trace = 6 4 2 3 1 2 5 3 1 2 4 2 3 1 2,
which is OK, since the trace vector shows how inefficient the original code is. Now my problem is, it is an assigment for a MOOC platform and the solution with the persistent variable won’t work because the the automated grader will run the function a number of times with random inputs and it will not clear the function. Without the persistent variable I must split the recursive calls in two code lines and I am struggling now to compute the nth fibonacci number:
Can anyone give a clue? The creation of the array works but I honestly don’t know how to deal with the two recursive call lines to compute the fibonacci. I am asked to profile an intentionally inefficient code. Following code will overtime with a huge input:
function f = fibo(n)
if n <= 2
f = 1;
else
f = fibo(n-2) + fibo(n-1);
end
end
I used a persistente variable, to create an array that reflects the recursion calls:
function [f, trace]=fibo_trace(n,v)%with persistent variable ‘trc’
persistent trc;
if isempty(trc)
trc=v;
end
if n<=2
trc=[trc n];
f=1;
else
trc=[trc n];
f=fibo_trace(n-2)+fibo_trace(n-1);
end
trace=trc;
end
That works flawlessly when I run the function with followin code:
[f trace] = fibo_trace(6,[])
And this is what the code returns:
f = 8
trace = 6 4 2 3 1 2 5 3 1 2 4 2 3 1 2,
which is OK, since the trace vector shows how inefficient the original code is. Now my problem is, it is an assigment for a MOOC platform and the solution with the persistent variable won’t work because the the automated grader will run the function a number of times with random inputs and it will not clear the function. Without the persistent variable I must split the recursive calls in two code lines and I am struggling now to compute the nth fibonacci number:
Can anyone give a clue? The creation of the array works but I honestly don’t know how to deal with the two recursive call lines to compute the fibonacci. fibonacci, recursion, homework MATLAB Answers — New Questions
How to set up the Matrix variables to use Options = optimoptions(‘lsqcurvefit’,’algorithm’,’levenberg-marquardt’)
I have two sets of M1 and M2 vectors (1×20) of experimental values that correspond to two sets of K1 and K2 inputs (1×20) respectively. Theoretlcal values of M1 and M2 (call them M1T and M2T) have a relationship with K1 and K2 such that M1-T is a function of K1 and K2, and M2-T is also a function of K1 and K2 with a series of a1 to a6 coefficients.
I am trying to find those a1 to a6 coefficients by minimizing the error function Total Error = (M1 – M1T)^2 + (M2-M2T)^2 by the use of
options = optimoptions(‘lsqcurvefit’,’Algorithm’,’levenberg-marquardt’), however, I don’t know how to set up my variables into these names/function (i.e. don’t know the approriate coding syntax).
As an example;
the inputs are: M1 = [ i1 i2 i3 ………… i20], M2 = [ i1 i2 i3 ………….i20], K1 = [ i1 i2 i3 ………… i20], K2 = [ i1 i2 i3 ………….i20],
the relationship between theroretical values of M1, M2 and the K1 and K2 are:
M1T(i) = a1*K1(i) + a2*K1(i)*K2(i) + a3*K2(i) + a4*(K1(i))^2
M2T(i) = a2*K2(i) + a2*K1(i) + a5*(K2(i))^2 + a6*K1(i)*K2(i)I have two sets of M1 and M2 vectors (1×20) of experimental values that correspond to two sets of K1 and K2 inputs (1×20) respectively. Theoretlcal values of M1 and M2 (call them M1T and M2T) have a relationship with K1 and K2 such that M1-T is a function of K1 and K2, and M2-T is also a function of K1 and K2 with a series of a1 to a6 coefficients.
I am trying to find those a1 to a6 coefficients by minimizing the error function Total Error = (M1 – M1T)^2 + (M2-M2T)^2 by the use of
options = optimoptions(‘lsqcurvefit’,’Algorithm’,’levenberg-marquardt’), however, I don’t know how to set up my variables into these names/function (i.e. don’t know the approriate coding syntax).
As an example;
the inputs are: M1 = [ i1 i2 i3 ………… i20], M2 = [ i1 i2 i3 ………….i20], K1 = [ i1 i2 i3 ………… i20], K2 = [ i1 i2 i3 ………….i20],
the relationship between theroretical values of M1, M2 and the K1 and K2 are:
M1T(i) = a1*K1(i) + a2*K1(i)*K2(i) + a3*K2(i) + a4*(K1(i))^2
M2T(i) = a2*K2(i) + a2*K1(i) + a5*(K2(i))^2 + a6*K1(i)*K2(i) I have two sets of M1 and M2 vectors (1×20) of experimental values that correspond to two sets of K1 and K2 inputs (1×20) respectively. Theoretlcal values of M1 and M2 (call them M1T and M2T) have a relationship with K1 and K2 such that M1-T is a function of K1 and K2, and M2-T is also a function of K1 and K2 with a series of a1 to a6 coefficients.
I am trying to find those a1 to a6 coefficients by minimizing the error function Total Error = (M1 – M1T)^2 + (M2-M2T)^2 by the use of
options = optimoptions(‘lsqcurvefit’,’Algorithm’,’levenberg-marquardt’), however, I don’t know how to set up my variables into these names/function (i.e. don’t know the approriate coding syntax).
As an example;
the inputs are: M1 = [ i1 i2 i3 ………… i20], M2 = [ i1 i2 i3 ………….i20], K1 = [ i1 i2 i3 ………… i20], K2 = [ i1 i2 i3 ………….i20],
the relationship between theroretical values of M1, M2 and the K1 and K2 are:
M1T(i) = a1*K1(i) + a2*K1(i)*K2(i) + a3*K2(i) + a4*(K1(i))^2
M2T(i) = a2*K2(i) + a2*K1(i) + a5*(K2(i))^2 + a6*K1(i)*K2(i) optimization, minimization algorithm MATLAB Answers — New Questions
How to seamlessly combine the two inputs given to the prismatic joint
Hello, I am currently conducting research on the 6-degree-of-freedom motion control of a Stewart platform using Simulink. I am creating the movement of the top platform by applying force input to the prismatic joints of the Stewart platform.
The algorithm conditions are as follows:
20-second simulation
Raise the actuators to the neutral position of 3.52m with a heave motion until 10 seconds.
Control the actuators to implement 6-degree-of-freedom motion from 10 seconds to 20 seconds.
Currently, I have completed the process of raising the actuators to the neutral position of 3.52m in step 2. However, to ensure continuity between step 2 and step 3, I need the input from step 2 and the input from step 3. I have implemented the inputs for both steps, but I am having difficulty combining the two inputs at the 10-second mark. Specifically, the actuators should rise to 3.52m until 10 seconds, and another input should be applied until 20 seconds in a continuous manner. I do not know how to make this transition smooth and continuous.Hello, I am currently conducting research on the 6-degree-of-freedom motion control of a Stewart platform using Simulink. I am creating the movement of the top platform by applying force input to the prismatic joints of the Stewart platform.
The algorithm conditions are as follows:
20-second simulation
Raise the actuators to the neutral position of 3.52m with a heave motion until 10 seconds.
Control the actuators to implement 6-degree-of-freedom motion from 10 seconds to 20 seconds.
Currently, I have completed the process of raising the actuators to the neutral position of 3.52m in step 2. However, to ensure continuity between step 2 and step 3, I need the input from step 2 and the input from step 3. I have implemented the inputs for both steps, but I am having difficulty combining the two inputs at the 10-second mark. Specifically, the actuators should rise to 3.52m until 10 seconds, and another input should be applied until 20 seconds in a continuous manner. I do not know how to make this transition smooth and continuous. Hello, I am currently conducting research on the 6-degree-of-freedom motion control of a Stewart platform using Simulink. I am creating the movement of the top platform by applying force input to the prismatic joints of the Stewart platform.
The algorithm conditions are as follows:
20-second simulation
Raise the actuators to the neutral position of 3.52m with a heave motion until 10 seconds.
Control the actuators to implement 6-degree-of-freedom motion from 10 seconds to 20 seconds.
Currently, I have completed the process of raising the actuators to the neutral position of 3.52m in step 2. However, to ensure continuity between step 2 and step 3, I need the input from step 2 and the input from step 3. I have implemented the inputs for both steps, but I am having difficulty combining the two inputs at the 10-second mark. Specifically, the actuators should rise to 3.52m until 10 seconds, and another input should be applied until 20 seconds in a continuous manner. I do not know how to make this transition smooth and continuous. simulink MATLAB Answers — New Questions
function must return a column vector
Hi, i am trying to plot some graphs for my my theses but i keep on getting error message..
find attached the code.. please help
function Juve_Model
clc;
%close all
global NO
%initial condition
Initial1 = [100,30,10,30];
hold on
for i=1:2:10
Initial=Initial1*i;
[t,u]=ode45(@hcv4,0:0.5:90, Initial);
subplot(2,2,1)
grid on
hold on
%axis([0 1400 0 1]);
plot(t,u(:,1),’linewidth’,3);
xlabel(‘Time (days)’)
ylabel(‘L’)
%*********************************************
subplot(2,2,2)
grid on
hold on
plot(t,u(:,2),’linewidth’,3);
xlabel(‘Time (days)’)
ylabel(‘F_1’)
%********************************************
subplot(2,2,3)
grid on
hold on
plot(t,u(:,3),’linewidth’,3);
xlabel(‘Time (days)’)
ylabel(‘F_2’)
%*******************************************
subplot(2,2,4)
grid on
hold on
plot(t,u(:,4),’linewidth’,3);
xlabel(‘Time (days)’)
ylabel(‘M’)
end
NO
end
function dy=hcv4(t,y)
%y=(L, F_1,F_2,M)=(y(1),y(2),y(3),y(4))
global NO
alpha=15; beta=0.1; q=0.3; gamma =0.7;
%beta=0.15; q=0.35; gamma=0.75;
K=1000; mu_L=0.35; d=0.45; mu_F1=0.15; mu_M=0.15; mu_F2=0.5;
% Basic Offspring (Reproduction) Number
NO=alpha*gamma*beta*q/(mu_F2*(mu_F1+gamma)*(beta+mu_L+d));
%Ordinary differential equation
dy(1)=alpha*(1-y(1)/K)*y(3)-(beta+mu_L+d)*y(1);
dy(2)=beta*q*y(1)-(mu_F1+gamma)*y(2);
dy(3)=gamma*y(2)-mu_F2*y(3);
dy(4)=beta*(1-q)*y(1)-mu_M*y(4);
endHi, i am trying to plot some graphs for my my theses but i keep on getting error message..
find attached the code.. please help
function Juve_Model
clc;
%close all
global NO
%initial condition
Initial1 = [100,30,10,30];
hold on
for i=1:2:10
Initial=Initial1*i;
[t,u]=ode45(@hcv4,0:0.5:90, Initial);
subplot(2,2,1)
grid on
hold on
%axis([0 1400 0 1]);
plot(t,u(:,1),’linewidth’,3);
xlabel(‘Time (days)’)
ylabel(‘L’)
%*********************************************
subplot(2,2,2)
grid on
hold on
plot(t,u(:,2),’linewidth’,3);
xlabel(‘Time (days)’)
ylabel(‘F_1’)
%********************************************
subplot(2,2,3)
grid on
hold on
plot(t,u(:,3),’linewidth’,3);
xlabel(‘Time (days)’)
ylabel(‘F_2’)
%*******************************************
subplot(2,2,4)
grid on
hold on
plot(t,u(:,4),’linewidth’,3);
xlabel(‘Time (days)’)
ylabel(‘M’)
end
NO
end
function dy=hcv4(t,y)
%y=(L, F_1,F_2,M)=(y(1),y(2),y(3),y(4))
global NO
alpha=15; beta=0.1; q=0.3; gamma =0.7;
%beta=0.15; q=0.35; gamma=0.75;
K=1000; mu_L=0.35; d=0.45; mu_F1=0.15; mu_M=0.15; mu_F2=0.5;
% Basic Offspring (Reproduction) Number
NO=alpha*gamma*beta*q/(mu_F2*(mu_F1+gamma)*(beta+mu_L+d));
%Ordinary differential equation
dy(1)=alpha*(1-y(1)/K)*y(3)-(beta+mu_L+d)*y(1);
dy(2)=beta*q*y(1)-(mu_F1+gamma)*y(2);
dy(3)=gamma*y(2)-mu_F2*y(3);
dy(4)=beta*(1-q)*y(1)-mu_M*y(4);
end Hi, i am trying to plot some graphs for my my theses but i keep on getting error message..
find attached the code.. please help
function Juve_Model
clc;
%close all
global NO
%initial condition
Initial1 = [100,30,10,30];
hold on
for i=1:2:10
Initial=Initial1*i;
[t,u]=ode45(@hcv4,0:0.5:90, Initial);
subplot(2,2,1)
grid on
hold on
%axis([0 1400 0 1]);
plot(t,u(:,1),’linewidth’,3);
xlabel(‘Time (days)’)
ylabel(‘L’)
%*********************************************
subplot(2,2,2)
grid on
hold on
plot(t,u(:,2),’linewidth’,3);
xlabel(‘Time (days)’)
ylabel(‘F_1’)
%********************************************
subplot(2,2,3)
grid on
hold on
plot(t,u(:,3),’linewidth’,3);
xlabel(‘Time (days)’)
ylabel(‘F_2’)
%*******************************************
subplot(2,2,4)
grid on
hold on
plot(t,u(:,4),’linewidth’,3);
xlabel(‘Time (days)’)
ylabel(‘M’)
end
NO
end
function dy=hcv4(t,y)
%y=(L, F_1,F_2,M)=(y(1),y(2),y(3),y(4))
global NO
alpha=15; beta=0.1; q=0.3; gamma =0.7;
%beta=0.15; q=0.35; gamma=0.75;
K=1000; mu_L=0.35; d=0.45; mu_F1=0.15; mu_M=0.15; mu_F2=0.5;
% Basic Offspring (Reproduction) Number
NO=alpha*gamma*beta*q/(mu_F2*(mu_F1+gamma)*(beta+mu_L+d));
%Ordinary differential equation
dy(1)=alpha*(1-y(1)/K)*y(3)-(beta+mu_L+d)*y(1);
dy(2)=beta*q*y(1)-(mu_F1+gamma)*y(2);
dy(3)=gamma*y(2)-mu_F2*y(3);
dy(4)=beta*(1-q)*y(1)-mu_M*y(4);
end global stability MATLAB Answers — New Questions
GCC Error When Compiling S-Function
I am attempting to compile an S-Function using the "mex" command in MATLAB. However, I encounter the following errors during the compilation process: GCC error create process: no such file or directory.
Can anybody help me resolve the issue ?I am attempting to compile an S-Function using the "mex" command in MATLAB. However, I encounter the following errors during the compilation process: GCC error create process: no such file or directory.
Can anybody help me resolve the issue ? I am attempting to compile an S-Function using the "mex" command in MATLAB. However, I encounter the following errors during the compilation process: GCC error create process: no such file or directory.
Can anybody help me resolve the issue ? r2017b MATLAB Answers — New Questions
How to merge a pie chart with a map
How to merge a pie chart with a map using MATLAB Mapping Toolbox? Just like this one.How to merge a pie chart with a map using MATLAB Mapping Toolbox? Just like this one. How to merge a pie chart with a map using MATLAB Mapping Toolbox? Just like this one. pie, mapp MATLAB Answers — New Questions
How to draw a pie chart in a map?
Hello! I want to ask how to draw some pie charts in a map by using the m_map package? And move the pie charts to the corresponding latitude and longitude position? Thanks!Hello! I want to ask how to draw some pie charts in a map by using the m_map package? And move the pie charts to the corresponding latitude and longitude position? Thanks! Hello! I want to ask how to draw some pie charts in a map by using the m_map package? And move the pie charts to the corresponding latitude and longitude position? Thanks! pie chart, m_map MATLAB Answers — New Questions
How to create the heat transfer between MA and MA and how to know the temperature and humidity of the outlet air in the cooling tower?
I am creating a MA heat recovery system in simscape (mainly to consider the recovery of condensate water) and need a heat exchanger for moist air to moist air. In addition, how to know the temperature and humidity of the cooling tower outlet?I am creating a MA heat recovery system in simscape (mainly to consider the recovery of condensate water) and need a heat exchanger for moist air to moist air. In addition, how to know the temperature and humidity of the cooling tower outlet? I am creating a MA heat recovery system in simscape (mainly to consider the recovery of condensate water) and need a heat exchanger for moist air to moist air. In addition, how to know the temperature and humidity of the cooling tower outlet? simscape, heat exchanger, cooling tower MATLAB Answers — New Questions
Editor doesn’t show what I write in comman
Just as the title says, I type all my requirements for HB in the command section but the editor doesn’t show any of my commands, when I try to save the page it just shows a blank command and editor sections, please helpJust as the title says, I type all my requirements for HB in the command section but the editor doesn’t show any of my commands, when I try to save the page it just shows a blank command and editor sections, please help Just as the title says, I type all my requirements for HB in the command section but the editor doesn’t show any of my commands, when I try to save the page it just shows a blank command and editor sections, please help help, homework MATLAB Answers — New Questions
How to import ‘kfoldPredict’ for old version matlab (2023a)
I want to use kfold with decision tree model. But kfoldpredict is for matlab 2024a.
Is there a possible way to import such function/ packages to matlab 2023?
I try save the class after open ‘kfoldpredict’ function, but it seems does not work.
Thank you for possible solutions.I want to use kfold with decision tree model. But kfoldpredict is for matlab 2024a.
Is there a possible way to import such function/ packages to matlab 2023?
I try save the class after open ‘kfoldpredict’ function, but it seems does not work.
Thank you for possible solutions. I want to use kfold with decision tree model. But kfoldpredict is for matlab 2024a.
Is there a possible way to import such function/ packages to matlab 2023?
I try save the class after open ‘kfoldpredict’ function, but it seems does not work.
Thank you for possible solutions. machine learning, kfold classification MATLAB Answers — New Questions
Memory consumption of the quad tree
Please, what is the memory consumption of the recursive quad tree decomposition procedure [S = qtdecomp(I)] with respect to the input set I?Please, what is the memory consumption of the recursive quad tree decomposition procedure [S = qtdecomp(I)] with respect to the input set I? Please, what is the memory consumption of the recursive quad tree decomposition procedure [S = qtdecomp(I)] with respect to the input set I? image segmentation MATLAB Answers — New Questions
Using transformer neural network for classification task
numChannels = inputSize;
maxPosition = 256;
numHeads = 4;
numKeyChannels = numHeads*32;
layers = [
sequenceInputLayer(numChannels,Name="input")
positionEmbeddingLayer(numChannels, maxPosition, Name="pos-emb");
additionLayer(2, Name="add")
selfAttentionLayer(numHeads,numKeyChannels,’AttentionMask’,’causal’)
selfAttentionLayer(numHeads,numKeyChannels)
indexing1dLayer("last")
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph, "input", "add/in2");
maxEpochs = 100;
miniBatchSize = 32;
learningRate = 0.001;
solver = ‘adam’;
shuffle = ‘every-epoch’;
gradientThreshold = 10;
executionEnvironment = "auto"; % chooses local GPU if available, otherwise CPU
options = trainingOptions(solver, …
‘Plots’,’training-progress’, …
‘MaxEpochs’, maxEpochs, …
‘MiniBatchSize’, miniBatchSize, …
‘Shuffle’, shuffle, …
‘InitialLearnRate’, learningRate, …
‘GradientThreshold’, gradientThreshold, …
‘ExecutionEnvironment’, executionEnvironment);
The input size is 12, so there are 12 features.
numClasses is 4, so I am classifying it into 4 class.
But it gives the following error when I try to run it
"
Error in test123_20240727 (line 195)
net=trainNetwork(XTrain, YTrain, layers, options);
Caused by:
Layer ‘add’: Unconnected input. Each layer input must be connected to the output of another layer.
"
line 195 is "net=trainNetwork(XTrain, YTrain, layers, options);"
Can anyone help me with this?numChannels = inputSize;
maxPosition = 256;
numHeads = 4;
numKeyChannels = numHeads*32;
layers = [
sequenceInputLayer(numChannels,Name="input")
positionEmbeddingLayer(numChannels, maxPosition, Name="pos-emb");
additionLayer(2, Name="add")
selfAttentionLayer(numHeads,numKeyChannels,’AttentionMask’,’causal’)
selfAttentionLayer(numHeads,numKeyChannels)
indexing1dLayer("last")
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph, "input", "add/in2");
maxEpochs = 100;
miniBatchSize = 32;
learningRate = 0.001;
solver = ‘adam’;
shuffle = ‘every-epoch’;
gradientThreshold = 10;
executionEnvironment = "auto"; % chooses local GPU if available, otherwise CPU
options = trainingOptions(solver, …
‘Plots’,’training-progress’, …
‘MaxEpochs’, maxEpochs, …
‘MiniBatchSize’, miniBatchSize, …
‘Shuffle’, shuffle, …
‘InitialLearnRate’, learningRate, …
‘GradientThreshold’, gradientThreshold, …
‘ExecutionEnvironment’, executionEnvironment);
The input size is 12, so there are 12 features.
numClasses is 4, so I am classifying it into 4 class.
But it gives the following error when I try to run it
"
Error in test123_20240727 (line 195)
net=trainNetwork(XTrain, YTrain, layers, options);
Caused by:
Layer ‘add’: Unconnected input. Each layer input must be connected to the output of another layer.
"
line 195 is "net=trainNetwork(XTrain, YTrain, layers, options);"
Can anyone help me with this? numChannels = inputSize;
maxPosition = 256;
numHeads = 4;
numKeyChannels = numHeads*32;
layers = [
sequenceInputLayer(numChannels,Name="input")
positionEmbeddingLayer(numChannels, maxPosition, Name="pos-emb");
additionLayer(2, Name="add")
selfAttentionLayer(numHeads,numKeyChannels,’AttentionMask’,’causal’)
selfAttentionLayer(numHeads,numKeyChannels)
indexing1dLayer("last")
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph, "input", "add/in2");
maxEpochs = 100;
miniBatchSize = 32;
learningRate = 0.001;
solver = ‘adam’;
shuffle = ‘every-epoch’;
gradientThreshold = 10;
executionEnvironment = "auto"; % chooses local GPU if available, otherwise CPU
options = trainingOptions(solver, …
‘Plots’,’training-progress’, …
‘MaxEpochs’, maxEpochs, …
‘MiniBatchSize’, miniBatchSize, …
‘Shuffle’, shuffle, …
‘InitialLearnRate’, learningRate, …
‘GradientThreshold’, gradientThreshold, …
‘ExecutionEnvironment’, executionEnvironment);
The input size is 12, so there are 12 features.
numClasses is 4, so I am classifying it into 4 class.
But it gives the following error when I try to run it
"
Error in test123_20240727 (line 195)
net=trainNetwork(XTrain, YTrain, layers, options);
Caused by:
Layer ‘add’: Unconnected input. Each layer input must be connected to the output of another layer.
"
line 195 is "net=trainNetwork(XTrain, YTrain, layers, options);"
Can anyone help me with this? transformer, neural network, machine learning, classification MATLAB Answers — New Questions
average values from .cvs file and plot
I want to calculate the hour by hour average values of the FIT column of the attached file, I have tried the following code but I could not solve the problem, then I want to graph the average data vs time
data1 = readtable(‘datos.csv’, ‘VariableNamingRule’,’preserve’);
MyDateTime = data1.Date + data1.Time;
MyDateTime.Format = ‘yyyy-MM-dd HH:mm:ss’;
data2 = [data1(:,1) table(MyDateTime) data1(:,[3:end])];
%%
% Create a new column for the time (round up to the start of the hour)
data.Hour = dateshift(data2.MyDateTime, ‘start’, ‘hour’);
% Group by new time column and calculate average
averageData = groupsummary(data2.MyDateTime, ‘Hour’, ‘mean’, ‘value’);
% Show results
disp(averageData);
% Graph average hourly data
figure;
plot(averageData.Hour, averageData.mean_value, ‘-o’);
xlabel(‘Date & Time’);
ylabel(‘Average value Pressure’);
title(‘Average Hour by Hour’);
grid on;
% Save results to a new CSV file
writetable(averageData, ‘promedios_hora_a_hora.csv’)I want to calculate the hour by hour average values of the FIT column of the attached file, I have tried the following code but I could not solve the problem, then I want to graph the average data vs time
data1 = readtable(‘datos.csv’, ‘VariableNamingRule’,’preserve’);
MyDateTime = data1.Date + data1.Time;
MyDateTime.Format = ‘yyyy-MM-dd HH:mm:ss’;
data2 = [data1(:,1) table(MyDateTime) data1(:,[3:end])];
%%
% Create a new column for the time (round up to the start of the hour)
data.Hour = dateshift(data2.MyDateTime, ‘start’, ‘hour’);
% Group by new time column and calculate average
averageData = groupsummary(data2.MyDateTime, ‘Hour’, ‘mean’, ‘value’);
% Show results
disp(averageData);
% Graph average hourly data
figure;
plot(averageData.Hour, averageData.mean_value, ‘-o’);
xlabel(‘Date & Time’);
ylabel(‘Average value Pressure’);
title(‘Average Hour by Hour’);
grid on;
% Save results to a new CSV file
writetable(averageData, ‘promedios_hora_a_hora.csv’) I want to calculate the hour by hour average values of the FIT column of the attached file, I have tried the following code but I could not solve the problem, then I want to graph the average data vs time
data1 = readtable(‘datos.csv’, ‘VariableNamingRule’,’preserve’);
MyDateTime = data1.Date + data1.Time;
MyDateTime.Format = ‘yyyy-MM-dd HH:mm:ss’;
data2 = [data1(:,1) table(MyDateTime) data1(:,[3:end])];
%%
% Create a new column for the time (round up to the start of the hour)
data.Hour = dateshift(data2.MyDateTime, ‘start’, ‘hour’);
% Group by new time column and calculate average
averageData = groupsummary(data2.MyDateTime, ‘Hour’, ‘mean’, ‘value’);
% Show results
disp(averageData);
% Graph average hourly data
figure;
plot(averageData.Hour, averageData.mean_value, ‘-o’);
xlabel(‘Date & Time’);
ylabel(‘Average value Pressure’);
title(‘Average Hour by Hour’);
grid on;
% Save results to a new CSV file
writetable(averageData, ‘promedios_hora_a_hora.csv’) average data MATLAB Answers — New Questions
How to save an output from Simulink into MatLab during different iteration ?
Hello,
I am running a CarMaker for Simulink simulation, where I have an output that I want to save. This Simulink .mdl is running multiple times with differents parameters automatically, and then during each new simulation, the new output overwrites the previous one into the MatLab workspace. How can I manage to save at each new simulation the ouput ?
Thank you in advance
PS: the output format is a timeseries, even though I’m not sur this really mattersHello,
I am running a CarMaker for Simulink simulation, where I have an output that I want to save. This Simulink .mdl is running multiple times with differents parameters automatically, and then during each new simulation, the new output overwrites the previous one into the MatLab workspace. How can I manage to save at each new simulation the ouput ?
Thank you in advance
PS: the output format is a timeseries, even though I’m not sur this really matters Hello,
I am running a CarMaker for Simulink simulation, where I have an output that I want to save. This Simulink .mdl is running multiple times with differents parameters automatically, and then during each new simulation, the new output overwrites the previous one into the MatLab workspace. How can I manage to save at each new simulation the ouput ?
Thank you in advance
PS: the output format is a timeseries, even though I’m not sur this really matters simulink, iteration MATLAB Answers — New Questions