Hi,
i found this code for the euler's method on the internet:
function [wi, ti] = euler ( RHS, t0, x0, tf, N )
neqn = length ( x0 );
ti = linspace ( t0, tf, N+1 );
wi = zeros( neqn, N+1 ) ;
wi(1:neqn, 1) = x0';
h = ( tf - t0 ) / N;
for i = 1:N
x0 = x0 + h * feval ( RHS, t0, x0 );
t0 = t0 + h;
wi(1:neqn,i+1) = x0';
end
% RHS string containing name of m-file defining the
% right-hand side of the differential equation; the
% m-file must take two inputs - first, the value of
% the independent variable; second, the value of the
% dependent variable
% t0 initial value of the independent variable
% x0 initial value of the dependent variable(s)
% if solving a system of equations, this should be a
% row vector containing all initial values
% tf final value of the independent variable
% N number of uniformly sized time steps to be taken to
% advance the solution from t = t0 to t = tf
%
% output:
% wi vector / matrix containing values of the approximate
% solution to the differential equation
% ti vector containing the values of the independent
% variable at which an approximate solution has been
% obtained
%
Now, I want to plot the result of the function. Unfortunately I wasn't able to solve this problem by my own.
I tried: plot(xo,to) and many other variations of this, but the result didn't make any sense.
Many thanks in advance, Fabian

댓글 수: 2

Youssef  Khmou
Youssef Khmou 2014년 12월 15일
can you briefly describe the input variables.
Amit
Amit 2014년 12월 15일
First question is: Do you know Euler's method? (if yes, it is a rather simple code and I think you should try it on your own - it will be a good exercise)
Second question is: where is your attempt or what have you done to understand this code?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2014년 12월 15일

댓글:

2014년 12월 15일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by