Take Home Exam (Gscomprog) By: Ma. Teresa Ramos-Abellera, ECE

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

TAKE HOME EXAM (GSCOMPROG)

By: Ma. Teresa Ramos- Abellera, ECE


Program #1 (GSNUMET)

Problem #1 : Solve ((sina/a)*(sina/a))-0.5 = 0 using Moss Method.

FLOWCHART

START

IE = 0.0000
RE =0.0000
X[8]
k=0
X0 =0.0000

PRINT “The manipulated form of ((sina/a)*(sina/a))-0.5 = 0 is a = 1.414 sin a."

READ IE

X0 = IE

PRINT “ k#0”

PRINT " X0 = " X[0]

k = k +1

YES
k<8 X[K] = (1.414)*(sinX[K-1])

NO RE = (X[k] - X[k-1])/(X[k])

STOP
A
1|Page
TAKE HOME EXAM (GSCOMPROG)
By: Ma. Teresa Ramos- Abellera, ECE

PRINT
"k#"k

PRINT
" X "k “ = “X

PRINT
" Relative error = "RE

PROGRAM

//Solve ((sina/a)*(sina/a))-0.5 = 0 using Moss Method.

#include <iostream.h>

#include<math.h>

int main()

{ double IE = 0.0000; //initial estimate

double RE = 0.0000; //relative error

double X [8]; //Values of a at 8 iterations

{for (int k=0; k<8;k++)

X[k] = 0;}

cout<<" The manipulated form of ((sina/a)*(sina/a))-0.5 = 0 is a = 1.414 sin a."<<endl<<endl;

cout<< "Assume an initial value of a. Enter initial value: ";

cin>> IE;

X[0] = IE;

cout<< " k#0"<<endl;

2|Page
TAKE HOME EXAM (GSCOMPROG)
By: Ma. Teresa Ramos- Abellera, ECE

cout<< " X[0] = "<<X[0]<<endl<<endl;

{for (int k=1; k<=8; k = k+1)

{ X[k]= (1.414)*(sin (X[k-1]));

RE = (X[k] - X[k-1])/(X[k]);

cout<< " k#"<<(k)<<endl;

cout<< " X["<<(k)<<"] = "<<X[k]<<endl;

cout<< " Relative error = "<<RE<< endl<<endl;

} }

return 0;}

3|Page
TAKE HOME EXAM (GSCOMPROG)
By: Ma. Teresa Ramos- Abellera, ECE
Program #2 (GSSTAT)

Problem #2: Cooking oils that are low in both cholesterol and saturated fats are often recommended for
people who are trying to lower their blood cholesterol level or to lose weight. Many cooking oils that have
no cholesterol still have saturated fat contents of 6% to 18%. Cooking oil made from soybeans has been
advertised as containing 15% saturated fats. A dietician thinks that the percentage of the saturated fats is
greater than15% and randomly selects 13 bottles of soybean cooking oil for testing. These bottles contain
the following percentages of saturated fats: 15.2, 12.4, 15.4, 13.5, 15.9, 17.1, 20.0, 16.9, 14.3, 19.1, 18.2,
15.5, and 16.316.9, 14.3, 19.1, 18.2, 15.5, and 16.3.

START

PercentSatFats[13] = {15.2, 12.4, 15.4, 13.5, 15.9, 17.1, 20.0,16.9, 14.3, 19.1, 18.2, 15.5,16.3}
total = 0.0
mean = 0.0
SumSqrM = 0.0
N=13
P = 15
SD = 0.0
t = 0.
df = 0.0
cv = 2.681

PRINT
" A. HYPOTHESIS "

PRINT
" Ho: P <= 15%"

PRINT
" Ho: P > 15%"

PRINT
" B. TEST STATISTICS "

4|Page
TAKE HOME EXAM (GSCOMPROG)
By: Ma. Teresa Ramos- Abellera, ECE

PRINT
" t = ((Mean -P)/SD)x sqrtN "

df = N - 1

PRINT
" C. CRITICAL REGION "

PRINT
" Level of significance, a = 0.01"

PRINT
" Degree of freedom, df = "

PRINT
" (Please see table for the critical value.)"

PRINT
" Critical value, Z = " cv

PRINT
" D. DECISION RULE"

5|Page
TAKE HOME EXAM (GSCOMPROG)
By: Ma. Teresa Ramos- Abellera, ECE

PRINT

" Computed value, tc => " cv " : Ho is rejected."

PRINT
" Computed value, tc < " cv " : Ho is not rejected."
" Computed value, tc => " cv " : Ho is rejected ."

PRINT

" E. COMPUTATION RESULTS"

C
x1 = x +1

x1<13
yes

D no

x2 = x +1 total = total + PercentSatFats[x]

no mean = total/N
E x1<13

C
yes

SumSqrM = SumSqrM +((mean - PercentSatFats[x])*(mean - PercentSatFats[x]))

SD = pow ((SumSqrM/N), 0.5)

6|Page
TAKE HOME EXAM (GSCOMPROG)
By: Ma. Teresa Ramos- Abellera, ECE

t = ((mean - P)/SD)* (pow (N, 0.5))

PRINT
" Computed t = "t

PRINT
“Mean of the percentages of saturated fats = "mean

PRINT
" Number of samples, N = " N

PRINT
" Standard deviation, SD = " SD

PRINT
" D. DECISION AND CONCLUSION"

no
t < cv
F

yes

PRINT
omputed value t = " t " is less than the critical value = "cv",""therefore, Ho is rejected. The cooking oil made from soybeans contains 15% sat

G
STOP

7|Page
TAKE HOME EXAM (GSCOMPROG)
By: Ma. Teresa Ramos- Abellera, ECE

PRINT
" Since the computed value t = " t " is greater than the critical value = "cv",""therefore, Ho
is not rejected. The cooking oil made from soybeans contains more tan 15% saturated
fats."

PROGRAM

//Cooking oils that are low in both cholesterol and saturated fats are often recommended

//for people who are trying to lower their blood cholesterol level or to lose weight. Many

//cooking oils that have no cholesterol still have saturated fat contents of 6% to 18%.

//Cooking oil made from soybeans has been advertised as containing 15% saturated fats.

//A dietician thinks that the percentage of the saturated fats is greater than 15% and

//randomly selects 13 bottles of soybean cooking oil for testing. These bottles contain

//the following percentages of saturated fats: 15.2, 12.4, 15.4, 13.5, 15.9, 17.1, 20.0,

//16.9, 14.3, 19.1, 18.2, 15.5, and 16.316.9, 14.3, 19.1, 18.2, 15.5, and 16.3.

#include <iostream.h>

#include <math.h>

int main()

{ float PercentSatFats[13] = {15.2, 12.4, 15.4, 13.5, 15.9, 17.1, 20.0,16.9, 14.3, 19.1, 18.2, 15.5,16.3};

float total = 0.0; //accumulator variable

float mean = 0.0; // average percentage of saturated fats

float SumSqrM = 0.0;

float N=13;

float P = 15; // standard of the dietician

float SD = 0.0;

float t = 0.0;

float df = 0.0;

8|Page
TAKE HOME EXAM (GSCOMPROG)
By: Ma. Teresa Ramos- Abellera, ECE
float cv = 2.681; // cv = 2.681

cout<< " A. HYPOTHESIS "<<endl;

cout<< " Ho: P <= 15%"<<endl;

cout<< " Ha: P > 15%"<<endl<<endl;

cout<< " B. TEST STATISTICS "<<endl;

cout<< " t = ((Mean -P)/SD)x sqrtN"<<endl<<endl;

df = N - 1;

cout<< " C. CRITICAL REGION "<<endl;

cout<< " Level of significance, a = 0.01"<<endl;

cout<< " Degree of freedom, df = "<<df<<endl;

cout<< " (Please see table for the critical value.)"<<endl;

cout<< " Critical value, Z = "<<cv<<endl<<endl;

cout<< " D. DECISION RULE"<<endl;

cout<< " Computed value, tc => "<<cv<<" : Ho is rejected."<<endl;

cout<< " Computed value tc < "<<cv<<" : Ho is not rejected."<<endl<<endl;

cout<< " E. COMPUTATION RESULTS"<<endl;

//Computation for the mean of the percentages of saturated fats

{ for ( int x=0; x<13; x=x+1)

total = total + PercentSatFats[x];

//calculate and display mean

mean = total/N;

//Computation for the standard deviation of the percentages of saturated fats

{ for (int x =0; x<13; x=x+1)

SumSqrM = SumSqrM +((mean - PercentSatFats[x])*(mean - PercentSatFats[x]));

SD = pow ((SumSqrM/N), 0.5);

//Computation of the t-test

9|Page
TAKE HOME EXAM (GSCOMPROG)
By: Ma. Teresa Ramos- Abellera, ECE
t = ((mean - P)/SD)* (pow (N, 0.5));

cout<< " Computed t = "<<t<<endl;

cout<< " Mean of the percentages of saturated fats = "<< mean<<endl;

cout<< " Number of samples, N = "<< N<<endl;

cout<< " Standard deviation, SD = "<< SD <<endl<<endl;

cout<< " D. DECISION AND CONCLUSION"<<endl;

//Formulation of conclusion

if (t < cv)

{cout<<" Since the computed value t = "<<t<<" is less than the critical value =
"<<cv<<","<<"therefore, Ho is rejected. The cooking oil made from soybeans contains 15% saturated
fats."<<endl; }

else

{cout<<" Since the computed value t "<<t<<" is greater than the critical value
"<<cv<<","<<"therefore, Ho is not rejected. The cooking oil made from soybeans contains more than 15%
saturated fats."<<endl;}

return 0;}

10 | P a g e
TAKE HOME EXAM (GSCOMPROG)
By: Ma. Teresa Ramos- Abellera, ECE
Program #3 (GSNUMET)

Problem #3 : Solve ((sina/a)*(sina/a))-0.5 = 0 using Moss Method.

FLOWCHART

START

IE = 0.0000
X [8]
FX =0.0000
FFX = 0.0000
RE = 0.0000
K1 =0
K2 =0

K1 = K + 1

K1<8 YES
X[K] = 0

NO

K2 = K2 +1

K2<=8
YES
A

NO

K2 = K2 +1

PRINT " K#"(k-1)

PRINT " FX = "FX

11 | P a g e
TAKE HOME EXAM (GSCOMPROG)
By: Ma. Teresa Ramos- Abellera, ECE

PRINT " FFX = "FFX

PRINT " Relative error, RE = "RE

PRINT " X" "["(k-1)"]" " = "X[k]

PRINT << " Number of iterations = " k-1

STOP

PROGRAM

//Solve cos^-1 = 0.52 using Wegstein Method.

#include <iostream.h>

#include<math.h>

int main()

{ double IE = 0.0000; //initial estimate

double X [8]; //iteration at k

double FX =0.0000 ;

double FFX = 0.0000;

double RE = 0.0000; //relative error

{for (int k=0; k<8;k++)

X[k] = 0;}

cout<< "Assume an initial value of a. Enter initial value: ";

cin>> IE;

X[0] = IE;

for (int k=1; k<=8; k = k+1)

{ FX = (cos(X[k-1])) + (X[k-1]) - (0.52);

12 | P a g e
TAKE HOME EXAM (GSCOMPROG)
By: Ma. Teresa Ramos- Abellera, ECE
FFX = (cos(FX)) + (FX) - (0.52);

X[k] = ((pow (FX,2)) - ((X[k-1])*(FFX)))/ ((2*FX)-(X[k-1])-(FFX)) ;

RE = abs(((X[k]) - (X[k-1]))/(X[k]));

cout<< " K#"<<k-1<<endl;

cout<< " FX = "<<FX<<endl;

cout<< " FFX = "<<FFX<<endl;

cout<< " Relative error, RE = "<<RE<<endl;

cout<< " X"<<"["<<k-1<<"]"<<" = "<<X[k]<<endl;

cout<< " Number of iterations = " <<k-1<<endl<<endl;}

return 0;}

13 | P a g e

You might also like