Numerical methods_C++_a formula

Hello friends,
My name is Veselin Nikiforov and I am a student of chemistry and informatics. For a course project please, if you can, for some help in this task, with which I can't cope alone. It is fell of me quite nasty theme ..
The condition of the post code is:
1) To introduce of the keyboard values ​​in the array Var1 (function EnterData1);
2) To introduce of the keyboard values ​​in the array Var2 (function EnterData2);
3) To display the input values ​​(functions PrintData1 and PrintData2);
4) To calculate the transition probabilities corresponding to both entries in the array Pout (function CalcModuleA).
All this works, no problem, but I must finish writing the code so the program to can continue with the calculation of one more equation //see attached image// http://dox.bg/files/dw?a=f34f797217
by using data obtained in the course of the decision in the array
Pout // function void CalcModuleA (int n)
Please if anyone can help, I will be grateful!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// DR.cpp : Defines the entry point for the console application.//

#include "stdio.h"
#include "math.h"
#include "string.h"
#include "stdlib.h"

double Var1[20][20];
double Var2[20];
double Pout[20][20];
const int n = 3;

void InitStr(char *str, int iSize)
{
int i= 0;
for(;i < iSize;i++)
str[i] = '\0';
}

void EnterData1(void)
{
int i = 0;
int j = 0;
int k = 0;
int iNext = 0;
char string[90000];
char str[90000];
InitStr(str, 90000);
InitStr(string, 90000);

printf("Enter the values for Var1 separated by ',' and ';' for new line: \n");
gets(string);
for(i = 0, k = 0; i < sizeof(string) || string[i] == '\0'; i++,j++)
{
if(string[i] == ';') { k++; iNext = 0; i++; }
if(string[i] == ',')
{
if(str[j] == '\0')
{//store data
Var1[k][iNext] = atof(str);
j = -1;
iNext++;
InitStr(str, 90000);
}
}
else
{
str[j] = string[i];
}
}
}

void EnterData2(void)
{
int i = 0;
int j = 0;
int iNext = 0;
char string[90000];
char str[90000];
InitStr(str, 90000);
InitStr(string, 90000);
printf("Enter the values for Var2 separated by ',': \n");
gets(string);
for(i = 0; i < sizeof(string) || string[i] == '\0'; i++,j++)
{
if(string[i] == ',')
{
if(str[j] == '\0')
{//store data
Var2[iNext] = atof(str);
j = -1;
iNext++;
InitStr(str, 90000);
}
}
else
{
str[j] = string[i];
}
}
}

void PrintData1(void)
{
for(int i = 0; i < 20;i++ )
for(int j = 0; j < 20 ; j++)
printf("[%d][%d] = %f\n",i,j,Var1[i][j]);
}

void PrintData2(void)
{
for(int i = 0; i < 20;i++ )
printf("[%d] = %f\n",i,Var2[i]);
}

void CalcModuleA(int n)
// here n is the number of comonomer - when the function call is actually set as a parameter (between 2 and 20 incl.) 
{
for(int i = 0; i < n; i++)
// i is an index of the row of Pout
{
double sum = 0.0;
// this sum goes to the i-th row of Pout 
for(int j = 0; j < n; j++)
sum += Var2[j] / Var1[i][j];
// this sum has already been calculated and can now calculate the i-th row of Pout 
for(int j = 0; j < n; j++)
Pout[i][j] = Var2[j] / (Var1[i][j] * sum);
// i-th row of Pout is ready and continue to the next ... 
}
}

int main(int argc, char* argv[])
{
char *s;
EnterData1();
EnterData2();
PrintData1();
PrintData2();
CalcModuleA(n);
gets(s);

return 0;
}
Last edited on
hey broder wat i can understand from the obe is this:
1: you take a set of values in a 2-D array Var1;
2: then you take another set of values in a 1-D array Var2;
3: then you define another 2-D array Pout to contain the transition probabilities;
4: Then you wish to get a formula to calculate the elements of the array F(i,k,l........) whose dimension is also not known(known by calculating the system).......given in the image........

As far as dimension of array F goes, it cant be defined at compile-time........
but i cant understand what do we mean by the constants i1,i2,i3,i4,i5,i6....etc. and a(i1)
used in the subscript of F and on the RHS................?

Hello my friend,
So this is not very easy to understand because this is physical-chemistry + mathematics ..:))
The formula is derived from Markov chains and aims to calculate the composition of the copolymer microstructure .. but that does not important. To here the program is running, no problem. Now I must write code for another formula and to connect them. The formula for the double and triple system should look like these examples in the picture. The values ​​of transition probabilities Pi,j are obtaining in the course of the decision of the array:Pout[i][j] = Var2[j] / (Var1[i][j] * sum);
If you can help me with writing code for the formula, I will find a way to connect them to the array Pout.
Can you help me bro?
Last edited on
Topic archived. No new replies allowed.