Mid-term MAE 2360 Fall 2020

docx

School

University of Texas, Arlington *

*We aren’t endorsed by this school

Course

2360

Subject

Aerospace Engineering

Date

Dec 6, 2023

Type

docx

Pages

6

Uploaded by MajorWillpowerBeaver8

Report
Mid-term of MAE 2360-001 Note : Exam period: 1:00 pm to 1:50pm, Wednesday, 10/28 for all students. There are five problems, and each is worth 20 points. For each problem, please Directly make modifications to the given C program, highlight your changes with a color, such as example. The modified C program is your answer. No need re-writing the C program. No need running the modified C program. No need giving the output of the modified C program. Open-book exam. A student can use and refer to anything during the exam. During the exam, not allowed to discuss or share information with anybody else. Please join the new conference to be opened on the Canvas website of MAE 2360-001, and turn on the camera of your computer, so we can see you on the conference during the exam period. Instruction for submission, which is the same as the way of submitting HWs Go on Canvas, select course MAE 2360-002 or 003 (depending on which lab session that you are enrolled in), then click on assignments and select Mid-term to be submitted and upload the document. The format in which the mid-term paper is to be submitted is only docx and doc. The time period given for the submission is 1-2pm, Wednesday, 10/28. The link for submission of the mid-term paper will disappear at 2pm and will be considered as “ not submitted”. If you get a problem to submit online, please email me immediately at chengluo@uta.edu to let me know the issue, with your exam paper attached to your email as the evidence that you have finished the exam. Two attempts will be allowed for the submission of the mid-term paper. Please do not copy others’ works, plagiarism check will be deployed to catch such an activity. 1
1. Fix 10 bugs in the following program. Highlight with a color the changes that you have made. #include <stdio.h> #include <math.h> #define EPS 1.0e-10 #define N 100 double x; double f(double x) { return pow(EPS,x)-3*x; } int main() { double x1, x2, x3; int count; printf("Enter xleft and xright separated by space ="); scanf("%lf %lf", &x1, &x2); for ( count=0;count> N; count+ +) { x3= (x1+x2)/2.0 ; if (f(x1)*f(x3)<0 ) x2=x3; else x1=x3; if ( f(x3)= =0.0 || fabs(x1-x2)< EPS ) break; } printf("iteration = %d\n", count ); print f("x= % lf\n", x1); return 0; } 2
2. The following C program is for summing up the first n terms of the infinite series Σ i =0 1 2 i = 1 + 1 2 + 1 4 + 1 8 + 1 16 + ... Please modify this C program to sum up the first n terms of the infinite series 1 + 1 2 4 + 1 3 4 + 1 4 4 + 1 5 4 + ...+ Highlight with a color the changes that you have made. #include <stdio.h> #include <math.h> int main() { int i, n; float sum=0.0; printf("Enter # of terms ="); scanf("%d", &n); for (i= 1; i< n ; i++) sum = sum + 1/pow( i,4); printf("Sum = %f \n",sum); return 0; } 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
3. The following C program uses Newton-Raphson method to solve x 2 - 2 = 0. Please modify this C program to solve x 2 -2x=-1 . Highlight with a color the changes that you have made. #include <stdio.h> #include <math.h> #define EPS 1.0e-10 double f(double x) { return x*x- 2*x+1; } double fp(double x) { return 2*x -2; } double newton(double x) { return x - f(x)/fp(x); } int main() { double x1, x2,difference; int i; printf("Enter initial guess ="); scanf("%lf", &x1); if (fp(x1)==0.0) { printf("No convergence.\n"); return 0; } for (i=0;i<100;i++) { x2=newton(x1); /* x 2 = x 1 -2- f ( x 1 )/ f ’( x 1 )*/ if (fabs(x1-x2)< EPS)break; x1=x2; } difference=x1*x1-2 *x1+1; /*check whether the left-hand side of the original equation is approximately zero.*/ printf("iteration = %d difference= %lf\n", i,difference); printf("x= %lf\n", x1); return 0; } 4
4. The C program below is to numerically differentiate a function given by the table below for x = 0.1 to x = 0.9 with the step size of h = 0.1. It uses central difference method. Now, we want to numerically differentiate the same function, using forward difference method. It is now for x = 0.0 to x = 0.9 with the step size of h = 0.1. Please modify the C program accordingly. Highlight with a color the changes that you have made. Time 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 f ( x ) 0 0.0998 0.1986 0.2955 0.3894 0.4794 0.5646 0.6442 0.7173 0.7833 0.8414 #include <stdio.h> #define N 11 int main() { double y[N]={0, 0.0998, 0.1986, 0.2955, 0.3894, 0.4794, 0.5646, 0.6442, 0.7173, 0.7833, 0.8414}; double foward[N], h=0.1; int i; for (i=1;i<N-1;i++) foward[i]= (y[i+1]-y[i-1])/(2*h); printf (" x Foward\n---------------------------\n"); for (i=1; i<N;i++) printf ("%lf %lf\n", i*h, foward[i]); return 0; } 5
5. The C program below is to numerically integrate Please modify this C program to numerically integrate /* Rectangular rule */ #include <stdio.h> double f(double x) {return x*x+2*x+1; } int main() { int i, n; double a= 2.0, b= 3.0, h, s=0.0, x ; printf("Number of partitions = "); scanf("%d", &n) ; h = (b-a)/n ; for (i= 0;i<n;i++) s = s + f(a + i*h) ; s=s*h ; printf("Result =%lf\n", s) ; return 0; } 6 ó õ 1 0 4 1+ x 2 dx, using rectangular rule. ó õ 3 2 ( x 2 +2x+1) dx .
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help