0% found this document useful (0 votes)
6 views15 pages

Assessment 1 problem solving task-combined

The document contains MATLAB code for defining and visualizing mathematical functions and solving a differential equation. It includes the creation of contour plots for a function T(x, y) and the computation of a double integral for a function d(x, y) to find the average depth. Additionally, it solves a differential equation using ode45 and compares the numerical solution with the exact solution.

Uploaded by

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

Assessment 1 problem solving task-combined

The document contains MATLAB code for defining and visualizing mathematical functions and solving a differential equation. It includes the creation of contour plots for a function T(x, y) and the computation of a double integral for a function d(x, y) to find the average depth. Additionally, it solves a differential equation using ode45 and compares the numerical solution with the exact solution.

Uploaded by

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

% Define the function T(x, y)

T = @(x, y) (1/3).*x.^3 + (5/2).*y.^2 - 5.*x.*y + 4.*x + 50;

% Create a contour plot using fcontour


fcontour(T, [0 5 0 5])

% Optional: Create a contour plot using contour with specified levels


x = linspace(0, 5, 100);
y = linspace(0, 5, 100);
[X, Y] = meshgrid(x, y);
Z = T(X,Y);
contour(X, Y, Z, [10 20 30 40 48 50 52 54 56 58 60 70 80 90 100])

Published with MATLAB® R2024a

1
% Define the function d(x, y)
d = @(x, y) (1/18) * y;

% Set up the integration limits


xmin = -6;
xmax = 6;
ymin = @(x) zeros(size(x)); % ymin as a function of x that returns 0
ymax = @(x) 36 - x.^2; % ymax as a function of x that returns 36 - x^2

% Compute the double integral


integral_value = integral2(d, xmin, xmax, ymin, ymax);

% Area A was computed previously as 288


A = 288;

% Calculate the average depth


average_depth = integral_value / A;

% Display the result


disp(average_depth);
0.8000

0.8000

ans =

0.8000

Published with MATLAB® R2024a

1
% Define the differential equation
f = @(t, Q) t.*exp(-t) - 3*Q;

% Initial condition
Q0 = 0;

% Time span
tspan = [0 10];

% Solve the differential equation using ode45


[t, Q] = ode45(f, tspan, Q0);

% Plot the numerical solution


figure;
plot(t, Q, 'b', 'LineWidth', 2);
xlabel('Time t');
ylabel('Charge Q(t)');
title('Numerical Solution of the Differential Equation using ode45');
grid on;

% Optionally: Plot the exact solution for comparison


Q_exact = @(t) 0.5*t.*exp(-t) - 0.25*exp(-t) + 0.25*exp(-3*t);
hold on;
plot(t, Q_exact(t), 'r--', 'LineWidth', 2);
legend('Numerical Solution', 'Exact Solution');
hold off;

1
Published with MATLAB® R2024a

You might also like