Uploaded by esraa.said

final Scientific Computations 1

advertisement
Department of Mathematics
Faculty of science
Time: 2 hours
Assiut University
Scientific Computations 1
Final exam
24/1/2023
Marks: 50
Course code: 451MC
Answer the following questions (50 marks)
Question No.1 : Choose the best single correct answer
(15 marks)
The following code shows how to estimate the value of π using Monte Carlo method
that works by randomly sampling points within a 2x2 square. Use the figure on the
right to answer the following four items:
--------------------------------------------
% Simulation parameters
square_area = 4;
N = 1000;
radius = 1;
MC_runs = 1000;
% Monte C arlo loop
for jj =1:MC_runs
hits = 0;
for n = 1:N
………………………①…………………;
………………………②…………………;
if (……………………………③…………………………)
hits = ……………………④……………………;
end
end
circle_area = hits/N * square_area;
pi_approximate(jj) = circle_area/radius*2;
end
---------------------------------------------1. Which of the following statement is valid in place number ① to Generate random point x?
a) x = 1 - rand(1,1)
c) x = 1 + rand(1,1)
2.
b) x = 1 - 2*rand(1,1)
d) x = 1 + 2*rand(1,1)
In number ② ,What is the correct statement to Generate random point y?
a) y = 1 - rand(1,1)
c) y = 1 + rand(1,1)
b) y = 1 + 2*rand(1,1)
d) y = 1 - 2*rand(1,1)
3. Which of the following is the true for test which points lie inside the circle, In number ③ ?
a) x^2 + y^2 < radius
c) x^2 + y^2 > radius
b) x^2 + y^2 > radius^2
d) x^2 + y^2 < radius^2
1
4. The appropriate way to calculate hits in the place number ④
a) hits + 2
b) hits - 1
c) hits + 1
𝒅𝟐 𝒙
d) hits - 2
𝒅𝒙
5. To solve the Legendre differential equation (𝟏 − 𝒕𝟐 ) 𝒅𝒕𝟐 − 𝟐𝒕 𝒅𝒕 + 𝒏(𝒏 + 𝟏)𝒙 = 𝟎 In MATLAB we use
the code:
a) syms t n; x1=dsolve('(1-t^2)*D2x-2*t*Dx+n*(n+1)*x=0','t')
b) syms t ; x1=dsolve('(1-t^2)D2x-2tDx+n(n+1)x=0','t')
c) x1=solve('(1-t^2)*D2x-2*t*Dx+n*(n+1)*x=0','x')
d) syms t n; x1=dsolve('(1-t^2)x’’-2*t*x’+n*(n+1)*x=0','x')
6. A command used to create a three-dimensional model of the molecule
and plot it in wolfram language (Mathematica)
a) Plot3D
b) Molecule
c) MoleculePlot3D
d) Plot
(𝐱−𝟏)(𝐱−𝟐)
7. To calculate the fourth derivative of this function √
(𝐱−𝟑)(𝐱−𝟒)
in MATLAB language, we use
the code
a) syms x; f=sqrt((x-1)*(x-2)/(x-3)/(x-4)); D=simple(diff(f,x,4))
b) syms x; f=sqrt((x-1)(x-2)/(x-3)/(x-4)); D=simple(diff(f,x,4))
c) f=sqrt((x-1)*(x-2)/(x-3)/(x-4));
D=simple(diff(f,x,4))
d) syms x; f=sqrt((x-1)*(x-2)/(x-3)/(x-4)); D=simple(diff4(f,x))
8. To draw the surface which equation giving by 𝒛 = 𝐬𝐢𝐧( 𝒙𝟐 + 𝒚𝟐 ) and
(x,y)ϵ[−1,1]×[−1,1]
in MATLAB language, we use the code
a) z= z=sin(x.^2-y.^2); surf(x,y,z)
b) [x,y]=meshgrid(-1:1:.1); z=sin(xy); plot(x,y,z)
c) [x,y]=meshgrid(-1:.1:1); z=sin(x.^2-y.^2);
surfc(x,y,z)
d) [x,y]=meshgrid(-1:.1:1); z=sin(x.^2-y.^2); plot(x,y,z)
9. To calculate the derivative of the function 𝒇(𝒙) = 𝒙𝟑𝒏 in Mathematica language we use the code
a) Diff[x^3n, x]
b) D[x^3n, x]
10. To Solve a linear pendulum equation:
c) syms x;D[x^n, x]
𝒅𝟐 𝒚
𝒅𝒙𝟐
d) syms x n; D[x^n, x]
+ 𝒚(𝒙) = 𝟎, 𝒚(𝟎) = 𝟏, 𝒚`(𝟎) = 𝟏/𝟑 in Mathematica
language we use the code
a) DSolve[{y''[x] + y[x] = = 0, y[0] = = 1, y'[0] = = 1/3}, y , x]
b) Solve[{y''[x] + y[x] = = 0, y[0] = = 1, y'[0] = = 1/3}, y , x]
c) Solvediff[{y''[x] + y[x] = = 0, y[0] = = 1, y'[0] = = 1/3}, y , x]
d) diffSolve[{y''[x] + y[x] = = 0, y[0] = = 1, y'[0] = = 1/3}, y , x]
2
The data in the following table are temperature readings from a chemical process in °C, taken
every half hour:
Time
1
1.5
2
2.5
3
3.5
4
4.5
5
Temperature
150
160
100
130
80
100
125
105
80
The following code using MATLAB program to
interpolate these data. Use the figure on the right
to answer the following five items :
--------------------------------% Linear interpolation
x = 1:0.5:5;
y = [150 160 100 130 80 100 125 105
80];
x_new = 0:.01:5;
y_new =……①……(x,y,x_new,'……②……');
plot(x,y,'rd'); hold;
…………③…… (x_new,y_new,'k');
hold; grid;
……④……('Linear interpolation')
ylabel('Temperature','fontsize',15)
xlabel('Time, index','fontsize',15)
…⑤……('Data Points','Linear Interpolation','fontsize',15)
axis([1 5 50 200]);
-----------------------------------------------11. Which one of the following functions is valid in place number ① ?
a) interp2
b) interp1
c) interp
d) interp3
12. In number ② ,which method is used to interpolate these data?
a) linear
b) nearest
c) spline
d) cubic
13. Which one of the following commands is true in number ③ to get the drawn figure?
a) surf
b) plot2d
c) plot3d
d) plot
14. In the place number ④ What is the command used to add a title to the figure
a) legand
b) lable
c) title
d) titlelable
15. In the place number ⑤ What is the command used to describe labels for each
plotted data
a) legand
b) lable
c) title
3
d) titlelable
Question No.2 :
Determine whether each of the following statements is true or false
(10 marks)
Consider an ordinary differential equation
dy/dx = x2 + y2, y(1) = 1.2 The following code
using the fourth order Runge-Kutta method
with step h=0.05
Answer the following four items
1- The number ① indicates the command n=(b-a)/h
2- In number ② , the correct method to calculate k2 is k2 = f(x(i) + h, y(i)+ k1/2(
3- The appropriate command for line ③ is y(i+1) = y(i) + (1/6)*(k1 + 2*(k2 + k3) + k4);
4- The value of k1 =2.11
The following code is used for drawing the figure on
the right; answer the following
four items:
[x,y] = ...①..(-12:0.5:12,-12:0.5:12);
r = sqrt(x.^2 + y.^2);
z = sin(r) ./ r;
figure
……②…(z)
....③.... cool
5- We use the command meshgrid in number ① to define the values of the variables x and y
6- To draw this surface in MATLAB we use the command surf in line number ②
7-The appropriate command in number ③ to change the colors of the 3D figure in MATLAB is
colormap
8- To add the names of the coordinates, we use the commands
X title ('x');y title ('y');z title ('z');
9- To generate a random number in the range (a,b) in the MATLAB program we use the
relationship a+(b-a)*rand(1,1)
10- If we want to substitute for each x with
𝒔−𝟏
𝒔+𝟏
into the function
𝒇 = 𝒙𝟓 + 𝟑𝒙𝟒 + 𝟒𝒙𝟑 + 𝟐𝒙𝟐 + 𝟑𝒙 + 𝟔
In MATLAB we use the code
syms x, f=x^5+3*x^4+4*x^3+2*x^2+3*x+6;
F=sub(f,x,(s-1)/(s+1))
4
End of Questions ,,,,,,,,,, With My Best Wishes ,,,,,,,
5
Download