without using built in functions create a function that solves the bvp d^2y/dt^2 + dy/dt = 0, y(0) = 0 and y(pi) = 6 for an arbitrary number of points nt in matlab

To solve the boundary value problem ( \frac{{d^2y}}{{dt^2}} + \frac{{dy}}{{dt}} = 0 ) with boundary conditions ( y(0) = 0 ) and ( y(\pi) = 6 ) using an arbitrary number of points ( nt ) in MATLAB, you can use the finite difference method.

Here's how you can create a function to solve this problem without using built-in functions in MATLAB:

main.m
function y = solve_bvp(nt)
    h = pi / (nt - 1); % Step size
    t = linspace(0, pi, nt); % Time points

    % Initialize y and v
    y = zeros(1, nt);
    v = zeros(1, nt);

    % Apply boundary conditions
    y(1) = 0;
    y(nt) = 6;

    % Solve the BVP
    for i = 2:(nt - 1)
        y(i + 1) = 2 * h * v(i) + y(i - 1) - h^2 * y(i);
        v(i + 1) = (y(i + 1) - y(i - 1)) / (2 * h);
    end

    % Return the solution
    y = y';
end
441 chars
22 lines

In this code, we create a function solve_bvp that takes the number of points nt as input and returns the solution y for the BVP. We use the finite difference method to approximate the second derivative and obtain the solution.

To use this function, simply call it with the desired number of points:

main.m
nt = 100; % Choose the number of points
y = solve_bvp(nt); % Solve the BVP

% Plot the solution
t = linspace(0, pi, nt);
plot(t, y);
xlabel('t');
ylabel('y');
title('Solution to BVP d^2y/dt^2 + dy/dt = 0');
207 chars
10 lines

This code will solve the BVP for 100 points and plot the solution.

Note that this is a simple implementation and there are more efficient and accurate methods for solving BVPs.

gistlibby LogSnag