simulating diabetes

I need help writing a c++ program for an assignment. The assignment is as follows:



A simple differential equation that describes S (sugar in grams per liter), the concentration of glucose in the blood stream as a function of time, is shown in equation 1. This equation shows that S decreases proportionately to the product of S and I (where I is the concentration of insulin in blood in milligrams per liter), and that S increases proportionately to the amount of glucose per body weight present in the digestive track (F/B = kg of glucose in digestive track divided by kg of body weight). The constants a and b are parameters that are determined from measurements of S and I vs. time for a given human.

Equation 1

The concentration of insulin (I) in the blood stream is modeled as a function of time using equation 2. This equation shows that the rate of insulin secretion by the pancreas increases proportionately to the sugar concentration, S, but that it decreases (metabolizes) proportionately to its concentration, I. Again, the constants c and g are parameters that are determined from measurements of S and I vs. time for a given human.

Equation 2

Program goal:

For this program, assume that the proportionality constants are a = 0.003, b = 1.0, and g = 0.0036. You will also be given data of S vs. time for a person with diabetes and for a person without diabetes, both with a value of F = 0.1 and B = 75. Your goal is to determine the value of the parameter c that best fits each set of data. Your final result will be the value of the constant c for a diabetic, and the constant c for a nondiabetic. [Hint: The value of c is between 0 and 0.01 for both the diabetic and the nondiabetic, and will be smaller for the diabetic.]

Program specifics:

Write a C++ program that does the following:

a. Reads in the S vs. t data in the file sugardata.txt, found by clicking here. This file contains the data for both the diabetic and the nondiabetic. It also contains some text which you must skip over using the getline function. We recommend you read the data into arrays.

b. Calls a void function that uses the bisection method to determine the value of c. Because there are two values of c to determine (one for the diabetic and one for the nondiabetic), you will call this bisection-method function twice. For the bisection method, use a tolerance of 0.001, and limit the maximum number of iterations to 100.

c. Your bisection-method function calls a single-result function that calculates the value of a best-fit error function. The best-fit error function (bfef) for this problem is the sum of the difference between the S data and the S calculated from the solution of the equations.

i.e. bfef = sum(Sdata,i - Seqn,i) Equation 3 (do not square the terms!)

d. Your single-result function that determines the best-fit error-function value must solve equations 1 and 2 simultaneously using Euler's method. Because the test data ranges from 0 to 1200 seconds, you must solve the equations from 0 to 1200 seconds. To assure accurate results, use a step size of 10 seconds for your Euler's-method solution (not the 100 seconds that the data is spaced). Use values of S = 0.9 and I = 0.1 as your initial conditions (at t = 0). Note that you will have to configure your program to select your Seqn values at every 100 second interval, and then subtract these values from the corresponding Sdata values to determine bfef.

e. For both cases (diabetic and nondiabetic), the main program prints to the screen, and to a file called results.txt, the value of c, the value of the best-fit error function, and the number of iterations the bisection method required to determine each c value.

And here is the sugar data:

non-diabetic then diabetic
t S
0 0.9
100 1.011
200 1.074
300 1.097
400 1.092
500 1.071
600 1.041
700 1.010
800 0.981
900 0.956
1000 0.936
1100 0.920
1200 0.909

0 0.90
100 1.028
200 1.143
300 1.244
400 1.334
500 1.412
600 1.479
700 1.535
800 1.583
900 1.624
1000 1.657
1100 1.684
1200 1.707

Any response will be helpful to me.
What exactly do you need help with?

what have you coded so far (if anything)?

Have you tried drawing out a path or structure chart?
Analysis shows that there are 724 words in your post and not a single question. So I will ask one; where are you stuck?

As a side note, I am one of the few contributers here who are still willing to explain why no one has helped you yet. Also this looks like an interesting assignment so do get back to us.
Last edited on
Here's my helpful response:
What is your question?
We don't give out answers around here. While it is perfectly possible that that is NOT what you are looking for (and I truly hope that's the case), you have not indicated any actual issues with your coding (assuming you have started) of this assignment. So you're going to need to get a lot more specific.
he forgot to attach the equation for S and I.

Equation 1)
dS/dt = -a*S*I +b*(F/B)

for this equation, he gave the values of a, b, F, and B.

where a= 0.003, b = 1.0, F = 0.1, B = 75

Equation 2)

dI/dt = c*S- g*I

g = 0.0036

Topic archived. No new replies allowed.