Category: Matlab
Category Archives: Matlab
Can I add units to the table?
Can I add units to the variables in the table? I have searched for information and I could not find anything, it can only be done in numbers …please helpCan I add units to the variables in the table? I have searched for information and I could not find anything, it can only be done in numbers …please help Can I add units to the variables in the table? I have searched for information and I could not find anything, it can only be done in numbers …please help units, tables, variables MATLAB Answers — New Questions
Creating a Square Matrix from a Variable “Plug-In”, Keeping Each Row In The Matrix Fixed To One Value
Hello everyone,
I am trying to create a square matrix that is N x N in size. In my case, N = 23.
I have a variable that’s called "Kernel". This variable is calculated as an equation in terms of "z" and "z_prime".
My values in z_prime will vary from L / 2N to (2N-1)*(L/2N) , in steps of "L/N".
My "z" variable will be fixed.
My goal is to generate a matrix with my "Kernel" variables that have different values of "z_prime", but keeping "z" fixed as a variable.
However, I need to keep each row of the "Kernel" matrix fixed to one "z_prime" value.
Which means each row will have its own "z_prime" value and thus each row will have its own "Kernel" value.
I attached my "value list" of "z_prime".
See excel sheet attached:
z_prime_value_list.xlsx
I attached a screenshot showing the type of matrix I am trying to generate
See .PNG file attached:
Kernel Matrix.png
…all the way until K(z,z_prime_23).
In my attempt, I have tried to use for loops and creating function handles to make it easier to generate this matrix. However, I still got a "1 x 23" matrix instead of the "23×23" matrix I was trying to get.
I attached my MATLAB Code for reference.
See MATLAB .m file attached:
Square_Matrix.m
I know that there is a way to use "nested" for loops to generate a square matrix of an "N X N" size. However, I wasn’t quite sure on how to implement that in MATLAB for my case.
I have tried to look through different questions/answers on the Mathworks Forum regarding square matrices. However, I wasn’t able to find anything that was relevant to my case.Hello everyone,
I am trying to create a square matrix that is N x N in size. In my case, N = 23.
I have a variable that’s called "Kernel". This variable is calculated as an equation in terms of "z" and "z_prime".
My values in z_prime will vary from L / 2N to (2N-1)*(L/2N) , in steps of "L/N".
My "z" variable will be fixed.
My goal is to generate a matrix with my "Kernel" variables that have different values of "z_prime", but keeping "z" fixed as a variable.
However, I need to keep each row of the "Kernel" matrix fixed to one "z_prime" value.
Which means each row will have its own "z_prime" value and thus each row will have its own "Kernel" value.
I attached my "value list" of "z_prime".
See excel sheet attached:
z_prime_value_list.xlsx
I attached a screenshot showing the type of matrix I am trying to generate
See .PNG file attached:
Kernel Matrix.png
…all the way until K(z,z_prime_23).
In my attempt, I have tried to use for loops and creating function handles to make it easier to generate this matrix. However, I still got a "1 x 23" matrix instead of the "23×23" matrix I was trying to get.
I attached my MATLAB Code for reference.
See MATLAB .m file attached:
Square_Matrix.m
I know that there is a way to use "nested" for loops to generate a square matrix of an "N X N" size. However, I wasn’t quite sure on how to implement that in MATLAB for my case.
I have tried to look through different questions/answers on the Mathworks Forum regarding square matrices. However, I wasn’t able to find anything that was relevant to my case. Hello everyone,
I am trying to create a square matrix that is N x N in size. In my case, N = 23.
I have a variable that’s called "Kernel". This variable is calculated as an equation in terms of "z" and "z_prime".
My values in z_prime will vary from L / 2N to (2N-1)*(L/2N) , in steps of "L/N".
My "z" variable will be fixed.
My goal is to generate a matrix with my "Kernel" variables that have different values of "z_prime", but keeping "z" fixed as a variable.
However, I need to keep each row of the "Kernel" matrix fixed to one "z_prime" value.
Which means each row will have its own "z_prime" value and thus each row will have its own "Kernel" value.
I attached my "value list" of "z_prime".
See excel sheet attached:
z_prime_value_list.xlsx
I attached a screenshot showing the type of matrix I am trying to generate
See .PNG file attached:
Kernel Matrix.png
…all the way until K(z,z_prime_23).
In my attempt, I have tried to use for loops and creating function handles to make it easier to generate this matrix. However, I still got a "1 x 23" matrix instead of the "23×23" matrix I was trying to get.
I attached my MATLAB Code for reference.
See MATLAB .m file attached:
Square_Matrix.m
I know that there is a way to use "nested" for loops to generate a square matrix of an "N X N" size. However, I wasn’t quite sure on how to implement that in MATLAB for my case.
I have tried to look through different questions/answers on the Mathworks Forum regarding square matrices. However, I wasn’t able to find anything that was relevant to my case. matrices, for loop, for loops, nested for loop, nested for loops, function handles MATLAB Answers — New Questions
Real time NI-DAQ data plot in Matlab with animatedline.
I tested this code and it works, but I would like to change it so that the time in seconds appears on the x-axis and not datetime. More precisely, I want to set the time limits of the x-axis to be between 0 and 10 seconds and then stop aquisition, so that I can display the signal from ni daq usb 6001. I also want that at the end of the acquisition, the entire signal remains displayed in the graph. Please, if possible, answer me.
As the code shows, I can read the data, live, but at the end of the 10 seconds the graph disappears, but I want it not to disappear. Once again, I want the x-axis to display the time in seconds and to remain stable (axis does not move, only the signal).
clear
close all
time = 0;
data = 0;
`% Set up the plot`
figure(1)
plotGraph = plot(time,data,’-r’ );
title(‘DAQ data log’,’FontSize’,15);
xlabel (‘Elapsed Time (s)’,’FontSize’,10)
ylabel(‘Voltage (V)’,’FontSize’,10);
h = animatedline;
ax = gca;
ax.YGrid = ‘on’;
ax.XGrid = ‘on’;
% Set up the data acquisition
dq = daq("ni");
ch1 = addinput(dq, "Dev1", "ai0", "Voltage");
dq.Rate = 1000;
% Start the data acquisition
start(dq, "Duration", seconds(10))
n = ceil(dq.Rate/10);
while ishandle(plotGraph)
data = read(dq, n);
voltage = data.Dev1_ai0;
t = datetime(‘now’);
for i = 1:100
% Add points to animated line
if isvalid(h)
addpoints(h, datenum(t), voltage(i))
end
end
% Update axes
ax.XLim = datenum([t-seconds(15) t]);
datetick(‘x’,’keeplimits’)
drawnow
end
disp(‘Plot Closed’)I tested this code and it works, but I would like to change it so that the time in seconds appears on the x-axis and not datetime. More precisely, I want to set the time limits of the x-axis to be between 0 and 10 seconds and then stop aquisition, so that I can display the signal from ni daq usb 6001. I also want that at the end of the acquisition, the entire signal remains displayed in the graph. Please, if possible, answer me.
As the code shows, I can read the data, live, but at the end of the 10 seconds the graph disappears, but I want it not to disappear. Once again, I want the x-axis to display the time in seconds and to remain stable (axis does not move, only the signal).
clear
close all
time = 0;
data = 0;
`% Set up the plot`
figure(1)
plotGraph = plot(time,data,’-r’ );
title(‘DAQ data log’,’FontSize’,15);
xlabel (‘Elapsed Time (s)’,’FontSize’,10)
ylabel(‘Voltage (V)’,’FontSize’,10);
h = animatedline;
ax = gca;
ax.YGrid = ‘on’;
ax.XGrid = ‘on’;
% Set up the data acquisition
dq = daq("ni");
ch1 = addinput(dq, "Dev1", "ai0", "Voltage");
dq.Rate = 1000;
% Start the data acquisition
start(dq, "Duration", seconds(10))
n = ceil(dq.Rate/10);
while ishandle(plotGraph)
data = read(dq, n);
voltage = data.Dev1_ai0;
t = datetime(‘now’);
for i = 1:100
% Add points to animated line
if isvalid(h)
addpoints(h, datenum(t), voltage(i))
end
end
% Update axes
ax.XLim = datenum([t-seconds(15) t]);
datetick(‘x’,’keeplimits’)
drawnow
end
disp(‘Plot Closed’) I tested this code and it works, but I would like to change it so that the time in seconds appears on the x-axis and not datetime. More precisely, I want to set the time limits of the x-axis to be between 0 and 10 seconds and then stop aquisition, so that I can display the signal from ni daq usb 6001. I also want that at the end of the acquisition, the entire signal remains displayed in the graph. Please, if possible, answer me.
As the code shows, I can read the data, live, but at the end of the 10 seconds the graph disappears, but I want it not to disappear. Once again, I want the x-axis to display the time in seconds and to remain stable (axis does not move, only the signal).
clear
close all
time = 0;
data = 0;
`% Set up the plot`
figure(1)
plotGraph = plot(time,data,’-r’ );
title(‘DAQ data log’,’FontSize’,15);
xlabel (‘Elapsed Time (s)’,’FontSize’,10)
ylabel(‘Voltage (V)’,’FontSize’,10);
h = animatedline;
ax = gca;
ax.YGrid = ‘on’;
ax.XGrid = ‘on’;
% Set up the data acquisition
dq = daq("ni");
ch1 = addinput(dq, "Dev1", "ai0", "Voltage");
dq.Rate = 1000;
% Start the data acquisition
start(dq, "Duration", seconds(10))
n = ceil(dq.Rate/10);
while ishandle(plotGraph)
data = read(dq, n);
voltage = data.Dev1_ai0;
t = datetime(‘now’);
for i = 1:100
% Add points to animated line
if isvalid(h)
addpoints(h, datenum(t), voltage(i))
end
end
% Update axes
ax.XLim = datenum([t-seconds(15) t]);
datetick(‘x’,’keeplimits’)
drawnow
end
disp(‘Plot Closed’) real-time-data, ni-usb-6001 MATLAB Answers — New Questions
To discribe Lmi term-regarding
Hai Team,
I am NARENSHAKTHI T. Recently working related to LMI tool box. Usually I used to represent the term as lmiterm([lmi 1 1 O1],-2,1), where O1 is a matrix. If I want to add an element’s inverse term as lmiterm([lmi 1 1 inv(O1)],-2,1), But it gives error. so i want your guidance team.
Thanks in adavanceHai Team,
I am NARENSHAKTHI T. Recently working related to LMI tool box. Usually I used to represent the term as lmiterm([lmi 1 1 O1],-2,1), where O1 is a matrix. If I want to add an element’s inverse term as lmiterm([lmi 1 1 inv(O1)],-2,1), But it gives error. so i want your guidance team.
Thanks in adavance Hai Team,
I am NARENSHAKTHI T. Recently working related to LMI tool box. Usually I used to represent the term as lmiterm([lmi 1 1 O1],-2,1), where O1 is a matrix. If I want to add an element’s inverse term as lmiterm([lmi 1 1 inv(O1)],-2,1), But it gives error. so i want your guidance team.
Thanks in adavance lmi term MATLAB Answers — New Questions
How to pull out data from cell array, concatenate it, and put into table for varying trials
Hello there, I have data from 10 trials stored in a 1×10 cell array "Predictors" and I want to create a loop that pulls out one trial at a time and then concatonates the data in all the other trials and saves it under a unique or numbered variable name? I am thinking something like this. I am not sure how to have it number each iteration:
for i = 1:length(Predictors)
Test_i = Predictors(i)
trainindicies_i = setdiff(1:length(Predictors),i);
Train_i = Predictors(trainindicies)
TrainX_i = vertcat(Train_i{:})
endHello there, I have data from 10 trials stored in a 1×10 cell array "Predictors" and I want to create a loop that pulls out one trial at a time and then concatonates the data in all the other trials and saves it under a unique or numbered variable name? I am thinking something like this. I am not sure how to have it number each iteration:
for i = 1:length(Predictors)
Test_i = Predictors(i)
trainindicies_i = setdiff(1:length(Predictors),i);
Train_i = Predictors(trainindicies)
TrainX_i = vertcat(Train_i{:})
end Hello there, I have data from 10 trials stored in a 1×10 cell array "Predictors" and I want to create a loop that pulls out one trial at a time and then concatonates the data in all the other trials and saves it under a unique or numbered variable name? I am thinking something like this. I am not sure how to have it number each iteration:
for i = 1:length(Predictors)
Test_i = Predictors(i)
trainindicies_i = setdiff(1:length(Predictors),i);
Train_i = Predictors(trainindicies)
TrainX_i = vertcat(Train_i{:})
end concatonate, tables, data formatting MATLAB Answers — New Questions
how to plot function with 2 variables? using fsolve or bisection ?
Y=(M_1-M_2^2)*Y^3+ 2X^2 (chi(1-M_1^2)- M_1*M_2)(chi*Y^2(1-M_2^2)+(2M_1+M_2)^Y-2chi*X^2+1=0
where
M_1-M_2=0.1
chi=0.5
X>0Y=(M_1-M_2^2)*Y^3+ 2X^2 (chi(1-M_1^2)- M_1*M_2)(chi*Y^2(1-M_2^2)+(2M_1+M_2)^Y-2chi*X^2+1=0
where
M_1-M_2=0.1
chi=0.5
X>0 Y=(M_1-M_2^2)*Y^3+ 2X^2 (chi(1-M_1^2)- M_1*M_2)(chi*Y^2(1-M_2^2)+(2M_1+M_2)^Y-2chi*X^2+1=0
where
M_1-M_2=0.1
chi=0.5
X>0 select tags from the drop down list MATLAB Answers — New Questions
Face Difficulty when converting tensorflow model to Matlab
I have a part of tensorflow code that I need to translate to matlab, but fail to do that. I have checked deep learning toolbox and unable to resolve the issue. If someone can help me this question, it is very helpful.
My tensorflow code (Python) is the following:
def get_r(model,tw,xw,a_data_n,mean_a,mean_u,kP,dim1,dim2,w1,stdt,stdx):
% A tf.GradientTape is used to compute derivatives in TensorFlow
with tf.GradientTape(persistent=True) as tape: % This makes you record the gradients on the tape for the parameters defined
tape.watch(tw) % This is needed to ‘follow’ the time, for automatic differentiation with respect to time
tape.watch(xw) % This is needed to ‘follow’ the position, for automatic differentiation with respect to position
a,u,p = model.net_u(tw,xw)
Px = tape.gradient(p, xw)
At = tape.gradient(a, tw)
ux = tape.gradient(u, xw)
ut = tape.gradient(u, tw)
My Matlab Code is the following: (notice that model.net_u input cannot accept dlarray format, dlarrya has to be done after model.net_u fucntion)
function get_r(model, tw, xw, a_data_n, mean_a, mean_u, kP, dim1, dim2, w1, stdt, stdx)
% Compute derivatives using the MATLAB automatic differentiation functionality
% Run the model
[a, u, p] = model.net_u(tw, xw);
a = dlarray(a);
tw = dlarray(tw);
xw = dlarray(xw);
% Compute gradients by iterating over each element
At = dlgradient(a, tw);
Px = dlgradient(p, xw);
ux = dlgradient(u, xw);
ut = dlgradient(u, tw);
end
Also, my a, u, p variable all have the shape 39600 * 1
My error message is
Error using dlarray/dlgradient (line 105)
Value to differentiate is not traced. It must be a traced real dlarray scalar. Use dlgradient inside a function called by dlfeval to
trace the variables.
Error in get_r (line 12)
At = dlgradient(sum(a, ‘all’), tw);
Can anyone point out how can I improve the code by adding dlfeval and other codes as well.
Additionally, sometimes when I add dlfeval, it will create the following error. What does this error mean?
Error using deep.internal.dlfevalWithNestingCheck (line 14)
Nested dlfeval calls are not supported. To compute higher derivatives, set the ‘EnableHigherDerivatives’ option of the dlgradient
function to true.
Error in dlfeval (line 31)
[varargout{1:nargout}] = deep.internal.dlfevalWithNestingCheck(fun,varargin{:});
Thanks for all suggestions!I have a part of tensorflow code that I need to translate to matlab, but fail to do that. I have checked deep learning toolbox and unable to resolve the issue. If someone can help me this question, it is very helpful.
My tensorflow code (Python) is the following:
def get_r(model,tw,xw,a_data_n,mean_a,mean_u,kP,dim1,dim2,w1,stdt,stdx):
% A tf.GradientTape is used to compute derivatives in TensorFlow
with tf.GradientTape(persistent=True) as tape: % This makes you record the gradients on the tape for the parameters defined
tape.watch(tw) % This is needed to ‘follow’ the time, for automatic differentiation with respect to time
tape.watch(xw) % This is needed to ‘follow’ the position, for automatic differentiation with respect to position
a,u,p = model.net_u(tw,xw)
Px = tape.gradient(p, xw)
At = tape.gradient(a, tw)
ux = tape.gradient(u, xw)
ut = tape.gradient(u, tw)
My Matlab Code is the following: (notice that model.net_u input cannot accept dlarray format, dlarrya has to be done after model.net_u fucntion)
function get_r(model, tw, xw, a_data_n, mean_a, mean_u, kP, dim1, dim2, w1, stdt, stdx)
% Compute derivatives using the MATLAB automatic differentiation functionality
% Run the model
[a, u, p] = model.net_u(tw, xw);
a = dlarray(a);
tw = dlarray(tw);
xw = dlarray(xw);
% Compute gradients by iterating over each element
At = dlgradient(a, tw);
Px = dlgradient(p, xw);
ux = dlgradient(u, xw);
ut = dlgradient(u, tw);
end
Also, my a, u, p variable all have the shape 39600 * 1
My error message is
Error using dlarray/dlgradient (line 105)
Value to differentiate is not traced. It must be a traced real dlarray scalar. Use dlgradient inside a function called by dlfeval to
trace the variables.
Error in get_r (line 12)
At = dlgradient(sum(a, ‘all’), tw);
Can anyone point out how can I improve the code by adding dlfeval and other codes as well.
Additionally, sometimes when I add dlfeval, it will create the following error. What does this error mean?
Error using deep.internal.dlfevalWithNestingCheck (line 14)
Nested dlfeval calls are not supported. To compute higher derivatives, set the ‘EnableHigherDerivatives’ option of the dlgradient
function to true.
Error in dlfeval (line 31)
[varargout{1:nargout}] = deep.internal.dlfevalWithNestingCheck(fun,varargin{:});
Thanks for all suggestions! I have a part of tensorflow code that I need to translate to matlab, but fail to do that. I have checked deep learning toolbox and unable to resolve the issue. If someone can help me this question, it is very helpful.
My tensorflow code (Python) is the following:
def get_r(model,tw,xw,a_data_n,mean_a,mean_u,kP,dim1,dim2,w1,stdt,stdx):
% A tf.GradientTape is used to compute derivatives in TensorFlow
with tf.GradientTape(persistent=True) as tape: % This makes you record the gradients on the tape for the parameters defined
tape.watch(tw) % This is needed to ‘follow’ the time, for automatic differentiation with respect to time
tape.watch(xw) % This is needed to ‘follow’ the position, for automatic differentiation with respect to position
a,u,p = model.net_u(tw,xw)
Px = tape.gradient(p, xw)
At = tape.gradient(a, tw)
ux = tape.gradient(u, xw)
ut = tape.gradient(u, tw)
My Matlab Code is the following: (notice that model.net_u input cannot accept dlarray format, dlarrya has to be done after model.net_u fucntion)
function get_r(model, tw, xw, a_data_n, mean_a, mean_u, kP, dim1, dim2, w1, stdt, stdx)
% Compute derivatives using the MATLAB automatic differentiation functionality
% Run the model
[a, u, p] = model.net_u(tw, xw);
a = dlarray(a);
tw = dlarray(tw);
xw = dlarray(xw);
% Compute gradients by iterating over each element
At = dlgradient(a, tw);
Px = dlgradient(p, xw);
ux = dlgradient(u, xw);
ut = dlgradient(u, tw);
end
Also, my a, u, p variable all have the shape 39600 * 1
My error message is
Error using dlarray/dlgradient (line 105)
Value to differentiate is not traced. It must be a traced real dlarray scalar. Use dlgradient inside a function called by dlfeval to
trace the variables.
Error in get_r (line 12)
At = dlgradient(sum(a, ‘all’), tw);
Can anyone point out how can I improve the code by adding dlfeval and other codes as well.
Additionally, sometimes when I add dlfeval, it will create the following error. What does this error mean?
Error using deep.internal.dlfevalWithNestingCheck (line 14)
Nested dlfeval calls are not supported. To compute higher derivatives, set the ‘EnableHigherDerivatives’ option of the dlgradient
function to true.
Error in dlfeval (line 31)
[varargout{1:nargout}] = deep.internal.dlfevalWithNestingCheck(fun,varargin{:});
Thanks for all suggestions! deep learning MATLAB Answers — New Questions
Error message using SPM command spm_jobman
Hi everyone,
I try to run an adapted preprocessing script (got it from an collegue) for a fMRI analysis. Unfortunatelly, I’m stuck on the command spm_jobman and get the following error message:
Error using spm_jobman>fill_run_job
No executable modules, but still unresolved dependencies or incomplete module inputs.
Error in spm_jobman (line 247)
sts = fill_run_job(‘run’, cjob, varargin{3:end});
Error in s03_preprocessing_with_slice_timing_batch_NICCUE (line 79)
spm_jobman(‘run’, matlabbatch);
It would be really helpful, if somebody could tell me what the problem is.
Thank you very much!
FranziskaHi everyone,
I try to run an adapted preprocessing script (got it from an collegue) for a fMRI analysis. Unfortunatelly, I’m stuck on the command spm_jobman and get the following error message:
Error using spm_jobman>fill_run_job
No executable modules, but still unresolved dependencies or incomplete module inputs.
Error in spm_jobman (line 247)
sts = fill_run_job(‘run’, cjob, varargin{3:end});
Error in s03_preprocessing_with_slice_timing_batch_NICCUE (line 79)
spm_jobman(‘run’, matlabbatch);
It would be really helpful, if somebody could tell me what the problem is.
Thank you very much!
Franziska Hi everyone,
I try to run an adapted preprocessing script (got it from an collegue) for a fMRI analysis. Unfortunatelly, I’m stuck on the command spm_jobman and get the following error message:
Error using spm_jobman>fill_run_job
No executable modules, but still unresolved dependencies or incomplete module inputs.
Error in spm_jobman (line 247)
sts = fill_run_job(‘run’, cjob, varargin{3:end});
Error in s03_preprocessing_with_slice_timing_batch_NICCUE (line 79)
spm_jobman(‘run’, matlabbatch);
It would be really helpful, if somebody could tell me what the problem is.
Thank you very much!
Franziska spm spm_jobman fmri MATLAB Answers — New Questions
how to modify this code to estimate LCOE using the parameters for offshore wind?
CAPEX ESTIMATION (KUSD)
% CAPEX OF WIND TURBINE
USD = 1000; Pwt = 400; dp = 30; Nwt = 50; Lcc = 10620; Acc = 6691; Loffs = 10; Lonsh = 2;
CAPwt = 1497.9 * Pwt^0.87; T = 20; WACC = 0.10;
% CAPEX OF BUILDING
CAbui = (0.9181 * dp^2 – 31.43 * dp + 747.4) * 1.09 * Pwt;
% CAPEX OF PROJECT MANAGEMENT
CApm = 130.82 * Pwt;
% CAPEX OF SUPERVISORY CONTROL AND DATA ACQUISITION
CAscda = 555.1 * Nwt;
% CAPEX OF ACQUISITION OF WIND POWER CONNECTION CABLES
CAawpc = ((4.26 * 10^-4 * Acc) + (2.324 * 10^-1)) * 1.09 * Lcc;
% INSTALLATION OF WIND POWER CONNECTION CABLES
CAiwpc = ((-2.2684 * 10^-3 * Nwt) + (3.8018 * 10^-1)) * 1.09 * Lcc;
% ACQUISITION OF OFFSHORE TRANSMISSION CABLES
CAaotc = ((3.3565 * 10^-3 * Pwt) + (8.3872 * 10^-2)) * Loffs * 1.09;
% CAPEX OF INSTALLATION OF OFFSHORE TRANSMISSION CABLES
CAiotc = ((-6.318 * 10^-4 * Pwt) + (3.8125 * 10^-1)) * 1.09 * Loffs;
% CAPEX OF ACQUISITION OF ONSHORE TRANSMISSION CABLES
CAaontc = ((-3.3565 * 10^-3 * Pwt) + (8.3872 * 10^-2)) * 0.27 * Lonsh;
% CAPEX OF INSTALLATION OF ONSHORE TRANSMISSION CABLES
CAiontc = 0.578 * Lonsh;
% Total CAPEX
CApexT = (CAPwt + CAbui + CApm + CAscda + CAawpc + CAiwpc + CAaotc + CAiotc + CAaontc + CAiontc);
CAXNEW = CApexT – 0.2 * CApexT;
% OPEX
Dexex = 0.003 * CApexT;
% TOTAL CAPEX IN NAIRA
CApexTN = CApexT * USD * 10^3;
% TOTAL OPEX AND DEXEX IN NAIRA
DexexN = Dexex * USD * 10^3;
Opex = 0.035 * CApexT;
OpexN = Opex * USD * 10^3;
n = 20; Rb = 10; AEPv = 28298304; Civ = 668860000; Cdex = 2006600; Cpex = 23410000;
% Calculate LCOE
AEP = 28298304;
lcoe = calculate_lcoe(CAXNEW, Opex, WACC, AEP, T);
% Display the LCOE
disp([‘The LCOE is ‘, num2str(lcoe), ‘ currency units per kWh’]);
% Function definition
function lcoe = calculate_lcoe(CAXNEW, Opex, WACC, AEP, T)
% Calculate the numerator of the LCOE formula
numerator = CAXNEW;
for t = 1:T
numerator = numerator + Opex / (1 + WACC)^t;
end
% Calculate the denominator of the LCOE formula
denominator = 0;
for t = 1:T
denominator = denominator + AEP / (1 + WACC)^t;
end
% Calculate the LCOE
lcoe = numerator / denominator;
endCAPEX ESTIMATION (KUSD)
% CAPEX OF WIND TURBINE
USD = 1000; Pwt = 400; dp = 30; Nwt = 50; Lcc = 10620; Acc = 6691; Loffs = 10; Lonsh = 2;
CAPwt = 1497.9 * Pwt^0.87; T = 20; WACC = 0.10;
% CAPEX OF BUILDING
CAbui = (0.9181 * dp^2 – 31.43 * dp + 747.4) * 1.09 * Pwt;
% CAPEX OF PROJECT MANAGEMENT
CApm = 130.82 * Pwt;
% CAPEX OF SUPERVISORY CONTROL AND DATA ACQUISITION
CAscda = 555.1 * Nwt;
% CAPEX OF ACQUISITION OF WIND POWER CONNECTION CABLES
CAawpc = ((4.26 * 10^-4 * Acc) + (2.324 * 10^-1)) * 1.09 * Lcc;
% INSTALLATION OF WIND POWER CONNECTION CABLES
CAiwpc = ((-2.2684 * 10^-3 * Nwt) + (3.8018 * 10^-1)) * 1.09 * Lcc;
% ACQUISITION OF OFFSHORE TRANSMISSION CABLES
CAaotc = ((3.3565 * 10^-3 * Pwt) + (8.3872 * 10^-2)) * Loffs * 1.09;
% CAPEX OF INSTALLATION OF OFFSHORE TRANSMISSION CABLES
CAiotc = ((-6.318 * 10^-4 * Pwt) + (3.8125 * 10^-1)) * 1.09 * Loffs;
% CAPEX OF ACQUISITION OF ONSHORE TRANSMISSION CABLES
CAaontc = ((-3.3565 * 10^-3 * Pwt) + (8.3872 * 10^-2)) * 0.27 * Lonsh;
% CAPEX OF INSTALLATION OF ONSHORE TRANSMISSION CABLES
CAiontc = 0.578 * Lonsh;
% Total CAPEX
CApexT = (CAPwt + CAbui + CApm + CAscda + CAawpc + CAiwpc + CAaotc + CAiotc + CAaontc + CAiontc);
CAXNEW = CApexT – 0.2 * CApexT;
% OPEX
Dexex = 0.003 * CApexT;
% TOTAL CAPEX IN NAIRA
CApexTN = CApexT * USD * 10^3;
% TOTAL OPEX AND DEXEX IN NAIRA
DexexN = Dexex * USD * 10^3;
Opex = 0.035 * CApexT;
OpexN = Opex * USD * 10^3;
n = 20; Rb = 10; AEPv = 28298304; Civ = 668860000; Cdex = 2006600; Cpex = 23410000;
% Calculate LCOE
AEP = 28298304;
lcoe = calculate_lcoe(CAXNEW, Opex, WACC, AEP, T);
% Display the LCOE
disp([‘The LCOE is ‘, num2str(lcoe), ‘ currency units per kWh’]);
% Function definition
function lcoe = calculate_lcoe(CAXNEW, Opex, WACC, AEP, T)
% Calculate the numerator of the LCOE formula
numerator = CAXNEW;
for t = 1:T
numerator = numerator + Opex / (1 + WACC)^t;
end
% Calculate the denominator of the LCOE formula
denominator = 0;
for t = 1:T
denominator = denominator + AEP / (1 + WACC)^t;
end
% Calculate the LCOE
lcoe = numerator / denominator;
end CAPEX ESTIMATION (KUSD)
% CAPEX OF WIND TURBINE
USD = 1000; Pwt = 400; dp = 30; Nwt = 50; Lcc = 10620; Acc = 6691; Loffs = 10; Lonsh = 2;
CAPwt = 1497.9 * Pwt^0.87; T = 20; WACC = 0.10;
% CAPEX OF BUILDING
CAbui = (0.9181 * dp^2 – 31.43 * dp + 747.4) * 1.09 * Pwt;
% CAPEX OF PROJECT MANAGEMENT
CApm = 130.82 * Pwt;
% CAPEX OF SUPERVISORY CONTROL AND DATA ACQUISITION
CAscda = 555.1 * Nwt;
% CAPEX OF ACQUISITION OF WIND POWER CONNECTION CABLES
CAawpc = ((4.26 * 10^-4 * Acc) + (2.324 * 10^-1)) * 1.09 * Lcc;
% INSTALLATION OF WIND POWER CONNECTION CABLES
CAiwpc = ((-2.2684 * 10^-3 * Nwt) + (3.8018 * 10^-1)) * 1.09 * Lcc;
% ACQUISITION OF OFFSHORE TRANSMISSION CABLES
CAaotc = ((3.3565 * 10^-3 * Pwt) + (8.3872 * 10^-2)) * Loffs * 1.09;
% CAPEX OF INSTALLATION OF OFFSHORE TRANSMISSION CABLES
CAiotc = ((-6.318 * 10^-4 * Pwt) + (3.8125 * 10^-1)) * 1.09 * Loffs;
% CAPEX OF ACQUISITION OF ONSHORE TRANSMISSION CABLES
CAaontc = ((-3.3565 * 10^-3 * Pwt) + (8.3872 * 10^-2)) * 0.27 * Lonsh;
% CAPEX OF INSTALLATION OF ONSHORE TRANSMISSION CABLES
CAiontc = 0.578 * Lonsh;
% Total CAPEX
CApexT = (CAPwt + CAbui + CApm + CAscda + CAawpc + CAiwpc + CAaotc + CAiotc + CAaontc + CAiontc);
CAXNEW = CApexT – 0.2 * CApexT;
% OPEX
Dexex = 0.003 * CApexT;
% TOTAL CAPEX IN NAIRA
CApexTN = CApexT * USD * 10^3;
% TOTAL OPEX AND DEXEX IN NAIRA
DexexN = Dexex * USD * 10^3;
Opex = 0.035 * CApexT;
OpexN = Opex * USD * 10^3;
n = 20; Rb = 10; AEPv = 28298304; Civ = 668860000; Cdex = 2006600; Cpex = 23410000;
% Calculate LCOE
AEP = 28298304;
lcoe = calculate_lcoe(CAXNEW, Opex, WACC, AEP, T);
% Display the LCOE
disp([‘The LCOE is ‘, num2str(lcoe), ‘ currency units per kWh’]);
% Function definition
function lcoe = calculate_lcoe(CAXNEW, Opex, WACC, AEP, T)
% Calculate the numerator of the LCOE formula
numerator = CAXNEW;
for t = 1:T
numerator = numerator + Opex / (1 + WACC)^t;
end
% Calculate the denominator of the LCOE formula
denominator = 0;
for t = 1:T
denominator = denominator + AEP / (1 + WACC)^t;
end
% Calculate the LCOE
lcoe = numerator / denominator;
end my research MATLAB Answers — New Questions
choose B or C or D if A does not exist – how to write this?
Hi all,
I have the following:
switch joint
case ‘Knee’
prox = ‘HipJC’;
dist = ‘LEPI’;
wand = ‘THPA’ ;
end
side = {‘R’,’L’};
for i = 1:length(side)
wandMk = data.([side{i},wand]).line;
end
I got the following error: Unrecognized field name "LTHPA", which is because ‘LTHPA’ does not exist in my structure.
I could use ‘THPP’ or ‘THDA’ or ‘THDP’ instead of ‘THPA’, because I know these exist. Hence, how could I rewrite the above for this to run?
For example:
if ‘THPA’ does not exist then
wand = ‘THDA’ or ‘THDA’ or ‘THDP’
Thanks!Hi all,
I have the following:
switch joint
case ‘Knee’
prox = ‘HipJC’;
dist = ‘LEPI’;
wand = ‘THPA’ ;
end
side = {‘R’,’L’};
for i = 1:length(side)
wandMk = data.([side{i},wand]).line;
end
I got the following error: Unrecognized field name "LTHPA", which is because ‘LTHPA’ does not exist in my structure.
I could use ‘THPP’ or ‘THDA’ or ‘THDP’ instead of ‘THPA’, because I know these exist. Hence, how could I rewrite the above for this to run?
For example:
if ‘THPA’ does not exist then
wand = ‘THDA’ or ‘THDA’ or ‘THDP’
Thanks! Hi all,
I have the following:
switch joint
case ‘Knee’
prox = ‘HipJC’;
dist = ‘LEPI’;
wand = ‘THPA’ ;
end
side = {‘R’,’L’};
for i = 1:length(side)
wandMk = data.([side{i},wand]).line;
end
I got the following error: Unrecognized field name "LTHPA", which is because ‘LTHPA’ does not exist in my structure.
I could use ‘THPP’ or ‘THDA’ or ‘THDP’ instead of ‘THPA’, because I know these exist. Hence, how could I rewrite the above for this to run?
For example:
if ‘THPA’ does not exist then
wand = ‘THDA’ or ‘THDA’ or ‘THDP’
Thanks! for loop, indexing, if statement MATLAB Answers — New Questions
how to get a good estimate of the positive parameters that will give a good fit of the curves to real data?
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 curve fitting, parameters estimation, optimization, multiple curve fitting MATLAB Answers — New Questions
How can I purchase a Student Version License if I don’t have a Credit Card?
How can I purchase a Student Version License if I don’t have a Credit Card?How can I purchase a Student Version License if I don’t have a Credit Card? How can I purchase a Student Version License if I don’t have a Credit Card? student, version, purchase, no, credit, card MATLAB Answers — New Questions
Why do I get an error when I try to acess the PDF files in the MATLAB 6.0 (R12) HelpDesk?
I get the following error when I try to acess the printable documentation, or PDF, files in the MATLAB 6.0 (R12) HelpDesk.
ERROR: Documentation in PDF format is located on your Documentation CD.
Insert the CD, then click OK to continue.
I installed all the documentation files when I installed MATLAB.I get the following error when I try to acess the printable documentation, or PDF, files in the MATLAB 6.0 (R12) HelpDesk.
ERROR: Documentation in PDF format is located on your Documentation CD.
Insert the CD, then click OK to continue.
I installed all the documentation files when I installed MATLAB. I get the following error when I try to acess the printable documentation, or PDF, files in the MATLAB 6.0 (R12) HelpDesk.
ERROR: Documentation in PDF format is located on your Documentation CD.
Insert the CD, then click OK to continue.
I installed all the documentation files when I installed MATLAB. pdf, doc, helpdesk, install MATLAB Answers — New Questions
How to calculate the determination coefficient R^2 with two matrix ?
hello I have two matrices A(i,j) and B (i,j). How to calculate for each i the covariance (A,B)? also calculate the determination coefficientR ^2?hello I have two matrices A(i,j) and B (i,j). How to calculate for each i the covariance (A,B)? also calculate the determination coefficientR ^2? hello I have two matrices A(i,j) and B (i,j). How to calculate for each i the covariance (A,B)? also calculate the determination coefficientR ^2? matrix, statistics MATLAB Answers — New Questions
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