Error "Function definitions are not permitted in this context" in matlab R2014a

I've tried to solve this system of equations: y_1 '=y_2 and y_2 '=-y_1 as follows:
clear all;
clc;
function dy = rigid(t,y)
dy = zeros(2,1);
dy(1) =y(2);
dy(2)=-y(1);
[T,Y] = ode113(@rigid,[0 12],[0 1 1]);
plot(T,Y(:,1),'-',T,Y(:,2),'-.')
but there's this error "Function definitions are not permitted in this context".
I was wondering if someone could help me about my problem.
Thanks in advance.

 Accepted Answer

You can not define functions on the command line. Open up a new file and edit it there
On the MATLAB menu bar HOME>New>Function

More Answers (1)

In R2014a, it was not permitted to define functions inside a script file.
Furthermore, functions defined inside a script file cannot be called from outside the script (not unless the script exports a copy of a handle to the function.)
You need to delete the lines
clear all;
clc;

Categories

Find more on Programming in Help Center and File Exchange

Tags

Asked:

on 7 Oct 2020

Answered:

on 7 Oct 2020

Community Treasure Hunt

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

Start Hunting!