0% found this document useful (0 votes)
8 views9 pages

Numerical Technique Assignment - Zewei Wang - x00180502

The document contains 5 questions related to numerical methods. Each question includes plots and code to solve equations numerically. Commentary is provided on solving equations with multiple roots or a compound root. The questions cover numerically solving systems of equations, implementing a Jacobian matrix, defining right-hand sides of ODEs, and solving a coupled system of ODEs describing two connected pendulums.

Uploaded by

tt1242281984
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views9 pages

Numerical Technique Assignment - Zewei Wang - x00180502

The document contains 5 questions related to numerical methods. Each question includes plots and code to solve equations numerically. Commentary is provided on solving equations with multiple roots or a compound root. The questions cover numerically solving systems of equations, implementing a Jacobian matrix, defining right-hand sides of ODEs, and solving a coupled system of ODEs describing two connected pendulums.

Uploaded by

tt1242281984
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Q1:

Figure 1: Plot of question 1

Figure 2: Solution of question 1


Q2:

Figure 3: Plot of question 2

Figure 4: Solution of question 2

Commentary on the solution process:


 Multiple roots: If the equation has multiple roots, the convergence is slower.

 Compound root: If the equation has a plural root, this method may not find them
unless the initial guess has plural parts.
 Derivatives of zero or near zero.
Q3:

Figure 5: Plot of question 3

Figure 6: Code and Result of question 3


Q4:

Figure 7: Plot of question 4

Q5:
Figure 8: Plot of question
Appendix:
Q1:

clear;

clc

%declare the functions, problem 1 on Lab sheet

syms f(x,y);

syms g(x,y);

f(x,y)=2-3.2*cos(x)-y^5+2.4*x;

g(x,y)=x^3+3*y^2-5;

%find their partial derivatives and the Jacobian

df_x=diff(f,x); % partial derivative of f with respect to x

df_y=diff(f,y);

dg_x=diff(g,x);

dg_y=diff(g,y);

J=[df_x df_y;dg_x dg_y]; % Jacobian matrix

%Get an intial guess for the solution after graphing (Geogebra)

x_0 = input('Enter initial approximate x coordinate:');

y_0 = input('Enter initial approximate y coordinate:');

accuracy=input('Enter the accuracy required in the form 10^(-n)')

%Create a 2D column vector and set an err value to start in while loop

Soln=[x_0;y_0];
err = 0.1;

steps = 0

while err>accuracy

Temp=Soln; %with digits at 6, vpa converts numbers to 6 digit values

b=eval(([f(Temp(1),Temp(2));g(Temp(1),Temp(2))]));

DeltaSoln=eval(J(Temp(1),Temp(2)))\b

Soln=Temp-DeltaSoln

err=max(abs(DeltaSoln(1)),abs(DeltaSoln(2)));

steps = steps+1

end

%Soln=eval(Soln);

disp(['The solution correct to ', num2str(accuracy), ' is (', num2str(Soln(1),-log10(accuracy)),


', ', num2str(Soln(2), -log10(accuracy)),')'])

disp(['The iteration took ', num2str(steps), ' steps'])

Q4:

function rhsderiv=rhsPairdetails(w,s, q)
% this function stores the details of the right hand side of a SET of ODEs
% of the form ds/dw = rhsderiv which is to to be solved numerically,
% where:
% w = independent variable (could use x)
% s = vector of two dependent variables (y and z)
% q = to allow for the passing of extra parameters
% rhsderiv, contains the details of the right hand side of the SET of
ODEs
% this is the example in the notes with f(x, ,y ,z) = x + y + z and
% g(x, y, z) = 1 + y + z

rhsderiv=[s(2), -s(2)-s(1)^3];
return;
Q5:

function rhsderiv = rhsPairdetails(w, s, q)

% w - independent variable

% s - vector of dependent variables, [theta1, omega1, theta2, omega2]

% q - allows for the passing of extra parameters (not used here)

rad1 = s(1);

w1 = s(2);

rad2 = s(3);

w2 = s(4);

%ode function

dtheta1_dt = w1;

domega1_dt = -10.2 * rad1 + 2.2 * rad2;

dtheta2_dt = w2;

domega2_dt = -10.2 * rad2 + 2.2 * rad1;

% Combine the derivatives into a single vector

rhsderiv = [s(2), -10.2 * s(1) + 2.2 * s(3), s(4) , -10.2 * s(3) + 2.2 * s(1)];

end

Enter initial independent variable value:

Enter initial value of first angle (theta1):

Enter initial value of first angular velocity (omega1):


-1.2

Enter initial value of second angle (theta2):

Enter initial value of second angular velocity (omega2):

Enter final value of independent variable you want calculated:

10

Enter the number of steps to use:

1000

You might also like