Question
I'm trying to run the following code in Matlab and I can't get around it: %--------------------------------------------------------------------------------------------------------------------------------- %Define modified euler function function euler(func, y0, delt,tf) %Compute
I'm trying to run the following code in Matlab and I can't get around it:
%---------------------------------------------------------------------------------------------------------------------------------
%Define modified euler function function euler(func, y0, delt,tf) %Compute t value t = 0:delt:tf; %Assign value y(1)=y0; %Loop for i = 1:length(t)-1 %Compute y value y(i+1) = y(i) + delt * feval(func,t(i) + delt/2, y(i) + delt*feval(func,t(i),y(i))); %Compute t t(i+1) = y0 + delt*i; end %Plot value plot(t,y) %Label xlabel('time') %Label ylabel('y') %Display disp(y(end)) end
%Define function function z = eqn(t) z = 14*t - 3; end %Plot fplot('',[0 10], 'r:') %Call method euler(@eqn,5,0.1,10)
%----------------------------------------------------------------------------------------------------------------------
Then I receive the following error:
>> euler Error: File: euler.m Line: 29 Column: 1 This statement is not inside any function. (It follows the END that terminates the definition of the function "eqn".)
Any help fixing the code to run would be helpful.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started