Consider the following equation: dy/dt = −20y+7e⁻⁰∙⁵ Given that the value of y=5 when t=0, a) Use the Euler's method to find y for t=0 to 0.1 using step size of Δt=0.01,0.001 and 0.0001 . Write a MATLAB code to do the calculations and show the results as a plot.

Sure! Here's a MATLAB code that implements Euler's method to solve the given differential equation and plot the results for different step sizes.

```matlab
% Parameters
t0 = 0; % initial time
y0 = 5; % initial value of y
h_vals = [0.01, 0.001, 0.0001]; % step sizes

% Solve the differential equation using Euler's method
for h = h_vals
t = t0:h:0.1; % time points
y = zeros(size(t)); % initialize y values
y(1) = y0; % initial condition

% Euler's method
for i = 1:length(t)-1
dydt = -20*y(i) + 7*exp(-0.5);
y(i+1) = y(i) + h*dydt;
end

% Plot the results
plot(t, y, 'DisplayName', sprintf('\\Delta t = %.4f', h)); hold on
end

% Add labels and legend
xlabel('t')
ylabel('y')
legend('Location', 'best')
```

This code will generate a plot showing the results for step sizes of 0.01, 0.001, and 0.0001.

Note: In the code, the term `exp(-0.5)` is used instead of `e^(-0.5)` to calculate the exponential function.

Sure! Here's a MATLAB code to solve the given differential equation using Euler's method and plot the results for different step sizes:

```matlab
% Define the differential equation dy/dt = -20y + 7e^(-0.5)
fun = @(t, y) -20*y + 7*exp(-0.5);

% Define the initial conditions
t0 = 0; % initial time
y0 = 5; % initial value

% Define the step sizes
step_sizes = [0.01, 0.001, 0.0001];

% Initialize empty arrays to store the results
t_results = cell(1, numel(step_sizes));
y_results = cell(1, numel(step_sizes));

% Solve the differential equation for each step size
for i = 1:numel(step_sizes)
dt = step_sizes(i);

% Initialize the arrays with initial values
t = t0:dt:0.1;
y = zeros(1, numel(t));
y(1) = y0;

% Apply Euler's method
for j = 2:numel(t)
y(j) = y(j-1) + dt * fun(t(j-1), y(j-1));
end

% Store the results
t_results{i} = t;
y_results{i} = y;
end

% Plot the results
figure;
hold on;
for i = 1:numel(step_sizes)
plot(t_results{i}, y_results{i});
end
legend(num2str(step_sizes'))
xlabel('t');
ylabel('y');
title('Euler''s method for dy/dt = -20y + 7e^(-0.5)');
```

This code defines the given differential equation, sets the initial conditions, and solves the equation using Euler's method for each step size. It then stores the results in arrays and plots them on the same figure, with each step size represented by a different color.