How to specify a 3 element column vector in Euler's Method for ODE
5 views (last 30 days)
Show older comments
I am writing code that will approximate the solution to an ODE IVP. I want the initual condition to be a 3D column array supplied by the user rather than one number becuase I am simulating a 3D vector , u(t) that changes in time. I am unsure how to make this initial condition 3D vector.
% u'(t) = F(t, u(t)) where u(t) = t^3 + 12t^2- 20t +1
% u(0) = v % note v is a vector
% solve du/dt = t^3 + 12t^2- 20t + 1 using euler method
% Euler's Method
% Initial conditions and setup
h=input('Enter the step size') % step size
t=0:h:4;%(starting time value 0):h step size
%(the ending value of t3 ); % the range of t
u=zeros(size(t)); % allocate the result y
%v=input('Enter the intial vector of 3 components using brackets') ??????????
u(1,1,1)=v; % the initial u as 3D. I GET ERROR AT THIS LINE
n=numel(u); % the number of u values
% The loop to solve the ODE
for i = 1:n-1
dudt= *t(i).^3 +12*t(i).^2 -20*t(i)+1 ; %the expression for u' in the ODE
u(i+1) = u(i)+dudt*h ;
fprintf('="Y"\n\t %0.01f',u(i));
end
%%fprintf('="U"\n\t %0.01f',u);
plot(t,u);
xlabel('t')
ylabel('u(t)')
grid on;
0 Comments
Accepted Answer
More Answers (1)
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!