fsolve in backward euler method
5 views (last 30 days)
Show older comments
Please help to implement fsolve for a third order ODE
%%
clear
close all
clc
%%
%% The differential equation is : x''' = 2 x'' + 6x
%Boundary condition
%x(0) =1, x'(0) = 0, x''(0)=1,
% Changing a third order differential equation into a system of linear
% equation
%x(1) = x ;
%%x(2) = x' = x(1)'
%x(3) = x'' = x(2)'
%x(3)' = 2 x(3) + 6 x(1)
t0 = 0; %initial value
x0 = [1;0;1]; %initial condition(given)
tEnd = 5; %end of time step
h = 0.001; %step size
N = (tEnd-t0)/h; %number of interval
T = t0:h:tEnd;
X = zeros(3, N+1); %a series of 3-element column vectors
X(:,1) = x0;
for i = 1:N
%fi = [X(2,i);X(3,i);2*X(3,i)+6*X(1,i)];
x = fsolve(@(x) x-X(:,i) - h* %%%%%%%%%); <-- problem.
X(:, i+1) = x;
end
%%
%ploting===================================================================
plot(T,X,'.','LineWidth',2);
title('Approximate solution Euler Implicit Method')
0 Comments
Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!