Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
restrepo
GitHub Repository: restrepo/ComputationalMethods
Path: blob/master/activities/test2_20161.ipynb
934 views
Kernel: Python 2

Test 2 - Computational Activity

This activity represents 50%50\% of the test 2. Each student must provide an ipython notebook with the solution of the proposed problems, along with all the performed procedures and related codes, as well as the obtained results.

The format used and comments are going to be taken into account.

Due to: ** Thursday May 26, Midnight**

Numerical differentiation

1. The crank AB of length R = 90 mm is rotating at constant angular speed of dθ/dt = 5000 rev/min. The position of the piston C can be shown to vary with the angle θ\theta as

x=R(cosθ+2.52sin2θ)x = R \left( \cos\theta + \sqrt{2.5^2-\sin^2\theta} \right)

Write a program that computes the acceleration of the piston at θ = 0◦, 5◦, 10◦, . . ., 180◦ by numerical differentiation.


###Kirchhoff Law in a Cubic circuit array

2. In electronics, it is commonly used the problem of a cubic circuit where all the resistances are equal. With this problem, it is tried to show that is not necessary to use the kirchhoff law but instead using some symmetry arguments, to get the equivalent resistance of the system.

But, what happens to the equivalent resistance of the system when one of the resistances is changed to a different value of R? The next system of equations is obtained applying kirchhoff law to the cubic circuit with all resistances R equal to the same value except a resistance r.

0=I1+I3+I5I130=I1+I2I80=I2+I4I60=I3I4I70=I5+I9+I120=I8I9+I110=I6I10I11+I130=I1R+I5R+I8R+I9R0=I2RI6R+I8RI11R0=I4RI6R+I7RI10R0=I3rI5RI7RI12R0=I1RI2R+I3rI4RV=I5R+I9R+I11R\begin{darray}{rcl} 0 = I_1 + I_3 + I_5 − I_{13}\\ 0 = −I_1 + I_2 − I_8\\ 0 = −I_2 + I_4 − I_6\\ 0 = −I_3 − I_4 − I_7\\ 0 = −I_5 + I_9 + I_{12}\\ 0 = I_8 − I_9 + I_{11}\\ 0 = I_6 − I_{10} − I_{11} + I_{13}\\ 0 = −I_1R + I_5R + I_8R + I_9R\\ 0 = I_2R − I_6R + I_8R − I_11R\\ 0 = −I_4R − I_6R + I_7R − I_10R\\ 0 = I_3r − I_5R − I_7R − I_{12}R\\ 0 = -I_1R − I_2R + I_3r − I_4R \\ V = I_5R + I_9R + I_{11}R \\ \end{darray}

Then, Find the equivalent resistance, varying the value of the resistance r on the cubic circuit. Does it grow increasing or decreasing r?

Make a plot of ReqR_{eq} vs rr in ohms where

Req=VI13\begin{equation*} R_{eq} = \frac{V}{I_{13}} \end{equation*}

Show that the result obtained for ReqR_{eq} when r=R coincides with the symmetry argument result (valid when all resistances in the circuit have the same value R) given by

Req=56R\begin{equation*} R_{eq} = \frac{5}{6}R \end{equation*}

For the sake of simplicity it can be used R=1$\Omega.Chooseavalue. Choose a value V$ you consider convinient.

###Gaussian Quadrature Rule

3 In contraposition with other methods as trapezoidal and Simpson rules that use a first-order or second-order Lagrange polynomial equally spaced, the gaussian quadrature rule chooses the points for evaluation in an optimal way. The nodes x1,x2,...,xnx_1,x_2,...,x_n in the interval [a,b][a,b] and coefficients c1,c2,...,cnc_1,c_2,...,c_n, are chosen to minimize the expected error obtained in the approximation

abf(x)dxi=1ncif(xi)\int_a^b f(x)dx \approx \sum_{i=1}^{n} c_if(x_i)

To illustrate the procedure for choosing the appropiate parameters, we will show how to select the coefficients and nodes when n=2n=2 (two point gauss quadrature) in the interval [a,b][a,b].

First, consider the next integral where a polynomial of third-order has been chosen to approximate the function, although a different order can be used

abf(x)dxc1f(x1)+c2f(x2)ab(a0+a1x+a2x2+a3x3)dxc1f(x1)+c2f(x2)a0x+a1x22+a2x33+a3x44abc1f(x1)+c2f(x2)a0(ba)+a1b2a22+a2b3a33+a3b4a44c1f(x1)+c2f(x2)\begin{darray}{rcl} \int_a^b f(x)dx &\approx& c_1f(x_1)+c_2f(x_2) \\ \int_a^b (a_0+a_1 x +a_2 x^2 +a_3x^3 ) dx &\approx& c_1f(x_1)+c_2f(x_2)\\ a_0x+a_1 \frac{x^2}{2} +a_2 \frac{x^3}{3} +a_3\frac{x^4}{4} |_a^b &\approx& c_1f(x_1)+c_2f(x_2) \\ a_0(b-a)+a_1 \frac{b^2-a^2}{2} +a_2 \frac{b^3-a^3}{3} +a_3\frac{b^4-a^4}{4} &\approx& c_1f(x_1)+c_2f(x_2) \end{darray}

but the right side is also equal to

abf(x)dxc1f(x1)+c2f(x2)=c1(a0+a1x1+a2x12+a3x13)+c2(a0+a1x2+a2x22+a3x23)=a0(c1+c2)+a1(c1x1+c2x2)+a2(c1x12+c2x22)+a3(c1x13+c2x23)\begin{darray}{rcl} \int_a^b f(x)dx &\approx& c_1f(x_1)+c_2f(x_2) \\ &=& c_1(a_0+a_1 x_1 +a_2 x_1^2 +a_3x_1^3 ) + c_2(a_0+a_1 x_2 +a_2 x_2^2 +a_3x_2^3 )\\ &=& a_0(c_1+c_2) + a_1(c_1x_1+c_2x_2) + a_2(c_1x_1^2+c_2x_2^2)+a_3(c_1x_1^3+c_2x_2^3) \end{darray}

equalling the last two expressions obtained for every coefficient aia_i, it is possible to obtain

c1=ba2;c2=ba2c_1 = \frac{b-a}{2}; \hspace{1cm} c_2 = \frac{b-a}{2}

and

x1=(ba2)(13)+b+a2;x2=(ba2)(13)+b+a2x_1 = \left(\frac{b-a}{2}\right)\left(\frac{-1}{\sqrt{3}} \right) + \frac{b+a}{2}; \hspace{1cm} x_2 = \left(\frac{b-a}{2}\right)\left(\frac{1}{\sqrt{3}} \right) + \frac{b+a}{2}

Hence,

abf(x)dxc1f(x1)+c2f(x2)=ba2f(ba2(13)+b+a2)+.ba2f(ba2(13)+b+a2)\begin{darray}{rcl} \int_a^b f(x)dx &\approx& c_1f(x_1)+c_2f(x_2) \\ &=& \frac{b-a}{2}f\left( \frac{b-a}{2}\left(\frac{-1}{\sqrt{3}} \right) + \frac{b+a}{2}\right) +\\ &. &\frac{b-a}{2}f\left( \frac{b-a}{2}\left(\frac{1}{\sqrt{3}} \right) + \frac{b+a}{2}\right) \end{darray}

Use the expression deduced for the two point gaussian quadrature to calculate the following integrals

11.5x2lnxdx01x2expxdx00.352x24dx0π/4exp3xsin(2x)dx\int_{1}^{1.5}x^2\ln xdx \\ \int_{0}^{1}x^2\exp^{-x}dx \\ \int_{0}^{0.35}\frac{2}{x^2-4}dx \\ \int_{0}^{\pi/4}\exp^{3x}\sin(2x)dx

find the error for the gaussian, composite trapezoidal and composite Simpson quadrature integration. Which one is the better approximation in every case?