fsolve in backward euler method
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!