Category: Matlab
Category Archives: Matlab
How do we get the linux device driver files matlab/hdl coder generatwes for the ipcore we made in matlab?
I am working on axi stream interface in zynq workflow which uses a symmetric fir filter IP with AXI stream and AXI4 lite interface to stream data and configure the filter coefficients.The steps i follwed gave me the output, but i wanted to go deeper to understand the backstage where i wanted to see the linux drivers for the ip files, i used terminal emulator ( teraterm to log in to the linux running on the zedboard, i saw the iio structure where my ip and its DMA’s were listed ) and also in the lib directory i saw the drivers too, so my qeustion is how is matlab creating those drivers, i couldnt find the corresponding c files and header files for it looking in the folder created by h dlcoder while running the example.
I did ‘lsmod’ in teraterm and found this :
zynq> lsmod
Module Size Used by Not tainted
mwipcore 3193 0
mwipcore_iio_streaming 9087 1 mwipcore
mwipcore_iio_sharedmem 11368 1 mwipcore
mwipcore_iio_mm 4414 1 mwipcore
mwipcore_dma_streaming 19767 1 mwipcore
mathworks_ip_common 9568 1 mwipcore
xilinx_dma
so my search was to find the c files corresponding to theses driver files that helps me to interface with the ip core created.The below given is how my folder looks like after running the Workflowadvisor.I am working on axi stream interface in zynq workflow which uses a symmetric fir filter IP with AXI stream and AXI4 lite interface to stream data and configure the filter coefficients.The steps i follwed gave me the output, but i wanted to go deeper to understand the backstage where i wanted to see the linux drivers for the ip files, i used terminal emulator ( teraterm to log in to the linux running on the zedboard, i saw the iio structure where my ip and its DMA’s were listed ) and also in the lib directory i saw the drivers too, so my qeustion is how is matlab creating those drivers, i couldnt find the corresponding c files and header files for it looking in the folder created by h dlcoder while running the example.
I did ‘lsmod’ in teraterm and found this :
zynq> lsmod
Module Size Used by Not tainted
mwipcore 3193 0
mwipcore_iio_streaming 9087 1 mwipcore
mwipcore_iio_sharedmem 11368 1 mwipcore
mwipcore_iio_mm 4414 1 mwipcore
mwipcore_dma_streaming 19767 1 mwipcore
mathworks_ip_common 9568 1 mwipcore
xilinx_dma
so my search was to find the c files corresponding to theses driver files that helps me to interface with the ip core created.The below given is how my folder looks like after running the Workflowadvisor. I am working on axi stream interface in zynq workflow which uses a symmetric fir filter IP with AXI stream and AXI4 lite interface to stream data and configure the filter coefficients.The steps i follwed gave me the output, but i wanted to go deeper to understand the backstage where i wanted to see the linux drivers for the ip files, i used terminal emulator ( teraterm to log in to the linux running on the zedboard, i saw the iio structure where my ip and its DMA’s were listed ) and also in the lib directory i saw the drivers too, so my qeustion is how is matlab creating those drivers, i couldnt find the corresponding c files and header files for it looking in the folder created by h dlcoder while running the example.
I did ‘lsmod’ in teraterm and found this :
zynq> lsmod
Module Size Used by Not tainted
mwipcore 3193 0
mwipcore_iio_streaming 9087 1 mwipcore
mwipcore_iio_sharedmem 11368 1 mwipcore
mwipcore_iio_mm 4414 1 mwipcore
mwipcore_dma_streaming 19767 1 mwipcore
mathworks_ip_common 9568 1 mwipcore
xilinx_dma
so my search was to find the c files corresponding to theses driver files that helps me to interface with the ip core created.The below given is how my folder looks like after running the Workflowadvisor. axi stream interface, matlab, hdlcoder MATLAB Answers — New Questions
The word’s font are not consistent.
I use the script to edit chinese, the font of output pdf file is not consistent with orignal script’s font.
orignal script file:
output file(pdf):I use the script to edit chinese, the font of output pdf file is not consistent with orignal script’s font.
orignal script file:
output file(pdf): I use the script to edit chinese, the font of output pdf file is not consistent with orignal script’s font.
orignal script file:
output file(pdf): script, font MATLAB Answers — New Questions
Why am I asked for my account credentials at every startup?
I am using Matlab R2016b on Linux Fedora 24.
Can I permanently set my account credentials so I am not asked at every startup?I am using Matlab R2016b on Linux Fedora 24.
Can I permanently set my account credentials so I am not asked at every startup? I am using Matlab R2016b on Linux Fedora 24.
Can I permanently set my account credentials so I am not asked at every startup? linux, startup, password, account MATLAB Answers — New Questions
How to draw a square with specific plot points
I’m trying to create two squares, one larger one, and the other within it.
I attempted to create one using matrices. I create one with x = [0 0 1 1] and y = [0 1 1 0]
I wanted a line to connect each one of the points, to thus create a line. However, when I did that, I only received three lines connect between the dots for some reason. The bottom points (0,0) and (1,0) for some reason were not connected. I then attempted to make a second square, and the same thing happened, with the two lower points in regards to their Y points did not connect. I tried using the rectangle function as well, but can’t get a square within a square to appear. Any help would be great. ThanksI’m trying to create two squares, one larger one, and the other within it.
I attempted to create one using matrices. I create one with x = [0 0 1 1] and y = [0 1 1 0]
I wanted a line to connect each one of the points, to thus create a line. However, when I did that, I only received three lines connect between the dots for some reason. The bottom points (0,0) and (1,0) for some reason were not connected. I then attempted to make a second square, and the same thing happened, with the two lower points in regards to their Y points did not connect. I tried using the rectangle function as well, but can’t get a square within a square to appear. Any help would be great. Thanks I’m trying to create two squares, one larger one, and the other within it.
I attempted to create one using matrices. I create one with x = [0 0 1 1] and y = [0 1 1 0]
I wanted a line to connect each one of the points, to thus create a line. However, when I did that, I only received three lines connect between the dots for some reason. The bottom points (0,0) and (1,0) for some reason were not connected. I then attempted to make a second square, and the same thing happened, with the two lower points in regards to their Y points did not connect. I tried using the rectangle function as well, but can’t get a square within a square to appear. Any help would be great. Thanks plotting MATLAB Answers — New Questions
Advanced matlab function autocompletion based on previous input
Hello Matlab community! first question for me:
Short question: is there an easy/documented way (or is it gonna be implemented in future releases) of providing input autocompletion for functions based on previous inputs?
Context: I found very useful the link below provided in other question/answer about autocompletion but it seems to me it has been somehow abandoned…
https://it.mathworks.com/help/matlab/matlab_prog/customize-code-suggestions-and-completions.html
the usage of mutuallyExclusiveGroup – Definition of set of exclusive arguments goes next by the desired result but not close enough.
To make a practical example my ideal result would be to get to the same user experience level that the function readcell(…) offers: if I provide an xls filename as first input and then type "sheet" matlab knows automatically the sheetnames of that file and suggest them. I tried to navigate inside the readcell(..) code but I think I’m missing something..
The autocompletion approach with the json template is kinda ‘static’ in my opinion, since I don’t know what file the user will enter, I can’t enumerate all the options manually, and I don’t know how to filter something more specific than a file-format like *mat, *xlsx,…
Any workaround? Or maybe I’m just not smart enough to make it work.
Another thing I use consistently for the autocompletion is the "argument (Input)" syntax for my purposes, usually I use
{mustBeMember(__,[option1, option2, ..]} and that helps me a lot to provide fast ways to make autocompletions for end users. But also in this situation I see no way to reuse the information of a previous input.. in example it could be cool, let’s say, having this:
function bill = iWannaEat( restaurant, dish) % < let’s keep things simple and assume this is a simple function, or a static method.
arguments (Input)
restaurant (1,1) KitchenObject
dish (1,:) string {mustBeMember(dish, restaurant.MenuSheet)} = "water" % < but I can’t reuse
% restaurant.MenuSheet,
% because a .MenuSheet must be guaranteed to exist?
end
bill = … things …
end
By the way I appreciate the extraordinary work you do for free to help other programmers with their things!!!
I went through 2014a till the 2024 and the developments has been huge, do you agree?
clc, clear allHello Matlab community! first question for me:
Short question: is there an easy/documented way (or is it gonna be implemented in future releases) of providing input autocompletion for functions based on previous inputs?
Context: I found very useful the link below provided in other question/answer about autocompletion but it seems to me it has been somehow abandoned…
https://it.mathworks.com/help/matlab/matlab_prog/customize-code-suggestions-and-completions.html
the usage of mutuallyExclusiveGroup – Definition of set of exclusive arguments goes next by the desired result but not close enough.
To make a practical example my ideal result would be to get to the same user experience level that the function readcell(…) offers: if I provide an xls filename as first input and then type "sheet" matlab knows automatically the sheetnames of that file and suggest them. I tried to navigate inside the readcell(..) code but I think I’m missing something..
The autocompletion approach with the json template is kinda ‘static’ in my opinion, since I don’t know what file the user will enter, I can’t enumerate all the options manually, and I don’t know how to filter something more specific than a file-format like *mat, *xlsx,…
Any workaround? Or maybe I’m just not smart enough to make it work.
Another thing I use consistently for the autocompletion is the "argument (Input)" syntax for my purposes, usually I use
{mustBeMember(__,[option1, option2, ..]} and that helps me a lot to provide fast ways to make autocompletions for end users. But also in this situation I see no way to reuse the information of a previous input.. in example it could be cool, let’s say, having this:
function bill = iWannaEat( restaurant, dish) % < let’s keep things simple and assume this is a simple function, or a static method.
arguments (Input)
restaurant (1,1) KitchenObject
dish (1,:) string {mustBeMember(dish, restaurant.MenuSheet)} = "water" % < but I can’t reuse
% restaurant.MenuSheet,
% because a .MenuSheet must be guaranteed to exist?
end
bill = … things …
end
By the way I appreciate the extraordinary work you do for free to help other programmers with their things!!!
I went through 2014a till the 2024 and the developments has been huge, do you agree?
clc, clear all Hello Matlab community! first question for me:
Short question: is there an easy/documented way (or is it gonna be implemented in future releases) of providing input autocompletion for functions based on previous inputs?
Context: I found very useful the link below provided in other question/answer about autocompletion but it seems to me it has been somehow abandoned…
https://it.mathworks.com/help/matlab/matlab_prog/customize-code-suggestions-and-completions.html
the usage of mutuallyExclusiveGroup – Definition of set of exclusive arguments goes next by the desired result but not close enough.
To make a practical example my ideal result would be to get to the same user experience level that the function readcell(…) offers: if I provide an xls filename as first input and then type "sheet" matlab knows automatically the sheetnames of that file and suggest them. I tried to navigate inside the readcell(..) code but I think I’m missing something..
The autocompletion approach with the json template is kinda ‘static’ in my opinion, since I don’t know what file the user will enter, I can’t enumerate all the options manually, and I don’t know how to filter something more specific than a file-format like *mat, *xlsx,…
Any workaround? Or maybe I’m just not smart enough to make it work.
Another thing I use consistently for the autocompletion is the "argument (Input)" syntax for my purposes, usually I use
{mustBeMember(__,[option1, option2, ..]} and that helps me a lot to provide fast ways to make autocompletions for end users. But also in this situation I see no way to reuse the information of a previous input.. in example it could be cool, let’s say, having this:
function bill = iWannaEat( restaurant, dish) % < let’s keep things simple and assume this is a simple function, or a static method.
arguments (Input)
restaurant (1,1) KitchenObject
dish (1,:) string {mustBeMember(dish, restaurant.MenuSheet)} = "water" % < but I can’t reuse
% restaurant.MenuSheet,
% because a .MenuSheet must be guaranteed to exist?
end
bill = … things …
end
By the way I appreciate the extraordinary work you do for free to help other programmers with their things!!!
I went through 2014a till the 2024 and the developments has been huge, do you agree?
clc, clear all input validation, code suggestion, autocompletion, previous input, function input, multiple, option based MATLAB Answers — New Questions
Unable to correctly import Spherical Parallel Manipulator CAD files into Simulink. kinematic constraints cannot be maintained error
I am currently working on programming a spherical parallel manipulator. I am very new to matlab and I also have minimal knowledge of programming and calculus.
When I import my onshape assembly into simulink and try to run the simulation I get an error saying that the kinematic constraints cannot be maintained. The simulation works for about 0.007 seconds before returning this error.
This is the exact error message:
An error occurred during simulation and the simulation was terminated
Caused by:
[‘V2_SPM_Assembly/Revolute9’, ‘V2_SPM_Assembly/Solver Configuration’]: ‘V2_SPM_Assembly/Revolute9’ kinematic constraints cannot be maintained. Check solver type and consistency tolerance in the Simscape Solver Configuration block. Check Simulink solver type and tolerances in Model Configuration Parameters. A kinematic singularity might be the source of this problem.
So far I have tried:
Turning down the tolerance. This results in the same error. Although the simulation works for about 0.108 seconds.
Changing the solver type. I tried all of the solver types and they do affect how long the simulation runs before resulting in an error but they never result in a simulation time greater than a second or so.
Redoing the CAD design. I remade the whole design and made sure that every axis of rotation is defined directly off of the origin.
Changing the order in which I assigned the revolute joints. This had no effect.
Replacing "revolute7", "revolute8", and "revolute9", with cylindrical joints. This resulted in a position violation error.
Changing how mate connectors were assigned in onshape part studios. I assigned mate connectors to be aligned with the relative axis of rotation and used those connectors in the joints. When I did not do this then the model resulted in a position violation error.
I have had minor success with:
Turning down the tolerance, and changing the way the joints are defined. I was able to get the model to simulate without an error. However, it only went through about 10 degrees of rotation on the base axis.
Changing the way the mate connectors where assigned in the onshape parts studios was the biggest improvement I have had and it made it so I stopped getting the position violation error.
Simulating the model with only one leg of the spherical parallel manipulator. This worked perfectly but it will not suffice for my project.
What I think the problem is:
I think that the part origins are the issue but I do not know how to correctly define them. The mate connectors help but I am unsure whether they act as coordinate systems for the parts. I have a Solidworks license but it is for Solidworks 2022 and it does not export to Simulink.
If anyone has any suggestions on what else I could try I would love to hear them. I linked my onshape file, and simulink file below as well as an image of the model.
https://cad.onshape.com/documents/d27868ad0436caa3f4afe2cb/w/a233bf5d473eb4ccb1022246/e/4dd27757644eec07373ecc70?renderMode=0&uiState=66542a76150c1c53248dd442I am currently working on programming a spherical parallel manipulator. I am very new to matlab and I also have minimal knowledge of programming and calculus.
When I import my onshape assembly into simulink and try to run the simulation I get an error saying that the kinematic constraints cannot be maintained. The simulation works for about 0.007 seconds before returning this error.
This is the exact error message:
An error occurred during simulation and the simulation was terminated
Caused by:
[‘V2_SPM_Assembly/Revolute9’, ‘V2_SPM_Assembly/Solver Configuration’]: ‘V2_SPM_Assembly/Revolute9’ kinematic constraints cannot be maintained. Check solver type and consistency tolerance in the Simscape Solver Configuration block. Check Simulink solver type and tolerances in Model Configuration Parameters. A kinematic singularity might be the source of this problem.
So far I have tried:
Turning down the tolerance. This results in the same error. Although the simulation works for about 0.108 seconds.
Changing the solver type. I tried all of the solver types and they do affect how long the simulation runs before resulting in an error but they never result in a simulation time greater than a second or so.
Redoing the CAD design. I remade the whole design and made sure that every axis of rotation is defined directly off of the origin.
Changing the order in which I assigned the revolute joints. This had no effect.
Replacing "revolute7", "revolute8", and "revolute9", with cylindrical joints. This resulted in a position violation error.
Changing how mate connectors were assigned in onshape part studios. I assigned mate connectors to be aligned with the relative axis of rotation and used those connectors in the joints. When I did not do this then the model resulted in a position violation error.
I have had minor success with:
Turning down the tolerance, and changing the way the joints are defined. I was able to get the model to simulate without an error. However, it only went through about 10 degrees of rotation on the base axis.
Changing the way the mate connectors where assigned in the onshape parts studios was the biggest improvement I have had and it made it so I stopped getting the position violation error.
Simulating the model with only one leg of the spherical parallel manipulator. This worked perfectly but it will not suffice for my project.
What I think the problem is:
I think that the part origins are the issue but I do not know how to correctly define them. The mate connectors help but I am unsure whether they act as coordinate systems for the parts. I have a Solidworks license but it is for Solidworks 2022 and it does not export to Simulink.
If anyone has any suggestions on what else I could try I would love to hear them. I linked my onshape file, and simulink file below as well as an image of the model.
https://cad.onshape.com/documents/d27868ad0436caa3f4afe2cb/w/a233bf5d473eb4ccb1022246/e/4dd27757644eec07373ecc70?renderMode=0&uiState=66542a76150c1c53248dd442 I am currently working on programming a spherical parallel manipulator. I am very new to matlab and I also have minimal knowledge of programming and calculus.
When I import my onshape assembly into simulink and try to run the simulation I get an error saying that the kinematic constraints cannot be maintained. The simulation works for about 0.007 seconds before returning this error.
This is the exact error message:
An error occurred during simulation and the simulation was terminated
Caused by:
[‘V2_SPM_Assembly/Revolute9’, ‘V2_SPM_Assembly/Solver Configuration’]: ‘V2_SPM_Assembly/Revolute9’ kinematic constraints cannot be maintained. Check solver type and consistency tolerance in the Simscape Solver Configuration block. Check Simulink solver type and tolerances in Model Configuration Parameters. A kinematic singularity might be the source of this problem.
So far I have tried:
Turning down the tolerance. This results in the same error. Although the simulation works for about 0.108 seconds.
Changing the solver type. I tried all of the solver types and they do affect how long the simulation runs before resulting in an error but they never result in a simulation time greater than a second or so.
Redoing the CAD design. I remade the whole design and made sure that every axis of rotation is defined directly off of the origin.
Changing the order in which I assigned the revolute joints. This had no effect.
Replacing "revolute7", "revolute8", and "revolute9", with cylindrical joints. This resulted in a position violation error.
Changing how mate connectors were assigned in onshape part studios. I assigned mate connectors to be aligned with the relative axis of rotation and used those connectors in the joints. When I did not do this then the model resulted in a position violation error.
I have had minor success with:
Turning down the tolerance, and changing the way the joints are defined. I was able to get the model to simulate without an error. However, it only went through about 10 degrees of rotation on the base axis.
Changing the way the mate connectors where assigned in the onshape parts studios was the biggest improvement I have had and it made it so I stopped getting the position violation error.
Simulating the model with only one leg of the spherical parallel manipulator. This worked perfectly but it will not suffice for my project.
What I think the problem is:
I think that the part origins are the issue but I do not know how to correctly define them. The mate connectors help but I am unsure whether they act as coordinate systems for the parts. I have a Solidworks license but it is for Solidworks 2022 and it does not export to Simulink.
If anyone has any suggestions on what else I could try I would love to hear them. I linked my onshape file, and simulink file below as well as an image of the model.
https://cad.onshape.com/documents/d27868ad0436caa3f4afe2cb/w/a233bf5d473eb4ccb1022246/e/4dd27757644eec07373ecc70?renderMode=0&uiState=66542a76150c1c53248dd442 onshape, simulink, smexportonshape, smimport, kinematic constraints, position violation, solidworks, cad, cad import, over defined, assembly, joints, revolute, spherical parallel manipulator, multibody MATLAB Answers — New Questions
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