0% found this document useful (0 votes)
24 views4 pages

Assignment 5 Alain Bezing

Uploaded by

Brionaca Carter
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)
24 views4 pages

Assignment 5 Alain Bezing

Uploaded by

Brionaca Carter
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/ 4

Assignment 5 (Individual Assignment – but you may consult others).

Find your value of y on Blackboard under DATA5. Fill in the blanks.


Your value of  = 1 (1pt)
Each blanked space is worth 1.5 points.
Your answers are to be those produced by second-order finite difference methods.
1) Consider the differential equation: f +(1+ {ψ} over {10.3} )f= on 0 < x < 2 with the
ψ df
| ψ
following boundary conditions: f ( 0 )=1+ 15 and dx =1+ 15 .
x=2

a. Using second-order finite difference equations with x = 1/3, find approximate


solution for f(x = 1), f(x = 1) ≅ _________ (+ 0.1%)
b. Using second-order finite difference equations with x = 1/6, find approximate
solution for f(x = 1), f(x = 1) ≅ _________ (+ 0.1%)

% Given parameters
psi = 1; % Example value, replace with your actual psi
dx1 = 1/3;
dx2 = 1/6;

% Function to solve the differential equation


function f_x_1 = solveDiffEq(dx, psi)
x = 0:dx:2; % Domain discretization
N = length(x);
A = zeros(N, N); % Coefficients matrix
B = ones(N, 1); % Constants vector (right-hand side of the equation)

% Fill the coefficients matrix A


for i = 2:N-1
A(i, i-1) = 1;
A(i, i) = -2 - dx^2 * (1 + psi / 10.3);
A(i, i+1) = 1;
end

% Apply boundary conditions


A(1, 1) = 1;
B(1) = 1 + psi / 15;
% Neumann boundary condition at x = 2 (using backward difference)
A(N, N-1) = -1;
A(N, N) = 1;
B(N) = dx * (1 + psi / 15);

% Solve the linear system


f = A\B;

% Find and return f(x = 1)


f_x_1 = interp1(x, f, 1);
end

% Solve for dx = 1/3 and dx = 1/6


f_x_1_dx1 = solveDiffEq(dx1, psi);
f_x_1_dx2 = solveDiffEq(dx2, psi);

fprintf('f(x = 1) with Δx = 1/3: ≈ %f\n', f_x_1_dx1);


fprintf('f(x = 1) with Δx = 1/6: ≈ %f\n', f_x_1_dx2);

2) Consider the differential equation: f +(1+ {ψ} over {10.3} )f'-f= on 0 < x < 2 with the
df
|
following boundary conditions: f ( 0 )=−1 and dx =1+ 15 .
x=2
ψ

a. Using second-order finite difference equations with x = 1/3, find approximate


solution for f(x = 1), f(x = 1) ≅ _________ (+ 0.1%)
b. Using second-order finite difference equations with x = 1/6, find approximate
solution for f(x = 1), f(x = 1) ≅ _________ (+ 0.1%)

% Given parameters
psi = 1; % Example value, replace with your actual psi
dx1 = 1/3;
dx2 = 1/6;

% Function to solve the differential equation


function f_x_1 = solveDiffEq(dx, psi)
x = 0:dx:2; % Domain discretization
N = length(x);
A = zeros(N, N); % Coefficients matrix
B = ones(N, 1); % Constants vector (right-hand side of the equation)

% Fill the coefficients matrix A


for i = 2:N-1
A(i, i-1) = 1 - dx/2 * (1 + psi / 10.3);
A(i, i) = -2 - dx^2 * (-1);
A(i, i+1) = 1 + dx/2 * (1 + psi / 10.3);
end

% Apply boundary conditions


A(1, 1) = 1; B(1) = -1;
% Neumann boundary condition at x = 2 (using backward difference)
A(N, N-1) = -1;
A(N, N) = 1;
B(N) = dx * (1 + psi / 15);

% Solve the linear system


f = A\B;

% Find and return f(x = 1)


f_x_1 = interp1(x, f, 1);
end

% Solve for dx = 1/3 and dx = 1/6


f_x_1_dx1 = solveDiffEq(dx1, psi);
f_x_1_dx2 = solveDiffEq(dx2, psi);

fprintf('f(x = 1) with Δx = 1/3: ≈ %f\n', f_x_1_dx1);


fprintf('f(x = 1) with Δx = 1/6: ≈ %f\n', f_x_1_dx2);

3) Consider a string (or flexible cable) with a weight attached to the end. Use second-order
finite difference equations to find approximations for the frequencies of the first and
second modes of natural vibration. Use the following:
L – string length = (1.0+/10.3) m
mc – mass of the string = 2.0 g
mp – mass of the weight = (1 + /10.3) g
x = (1.0+/10.3) /3 m.
f1 ≅ ________ Hz (+ 0.1%)
f2 ≅ ________ Hz (+ 0.1%)

% Given parameters
psi = 1; % Replace with the actual value of ψ
L = 1.0 + psi / 10.3;
mc = 2.0; % Total mass of the string in grams
mp = 1 + psi / 10.3; % Mass of the weight in grams
delta_x = L / 3;
n = round(L / delta_x); % Number of segments
m_segment = mc / n; % Mass per segment

% Constructing the matrix for the system


K = zeros(n,n); % Stiffness matrix
for i = 1:n-1
K(i, i) = 1;
K(i, i+1) = -0.5;
K(i+1, i) = -0.5;
end
K(n, n) = 1; % Last segment

% Adjust the last mass for the weight


M = diag([repmat(m_segment, 1, n-1), m_segment + mp]); % Mass matrix

% Solve the eigenvalue problem


[A, B] = eig(K, M);
eigenvalues = diag(B);
% Frequencies in Hz
frequencies = sqrt(eigenvalues) / (2 * pi);

% Display the first two frequencies


fprintf('First mode frequency: %f Hz\n', frequencies(1));
fprintf('Second mode frequency: %f Hz\n', frequencies(2));

You might also like