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

5 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Jon
Jon le 7 Oct 2020
Modifié(e) : Jon le 7 Oct 2020
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

Plus de réponses (1)

Walter Roberson
Walter Roberson le 7 Oct 2020
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;

Catégories

En savoir plus sur Entering Commands dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by