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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!