Please help me sir i am stuck in matlab with a program. Sir, I am using MATLAB 2015a while running a program as below for I get an error like this "Error: Function definitions are not permitted in this context."
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
function dhdt = tankfill(t,h)
A = 10 + 4*sin(t);
H = 2*sqrt(h);
dhdt = A - H;
tspan = [0 30];
h0 = 1;
[t,h] = ode45(tankfill,tspan,h0);
plot(t,h)
Error: Function definitions are not permitted in this context.
0 comentarios
Respuestas (1)
Walter Roberson
el 5 de Mzo. de 2018
Editada: Walter Roberson
el 5 de Mzo. de 2018
You need to store the first four lines of that code in a file named tankfill.m, but the lines starting from the assignment to tspan should either go into a different file or should go on the command line.
In R2015a it was never valid to try to define a function at the command line, and it was never valid to try to define a function inside a script file (a script file is any .m file whose first executable line is not 'function' or 'classdef'). A later MATLAB release made it possible to define functions inside script files in some circumstances, but even in the very latest versions it is never valid to define a function at the command line.
4 comentarios
Walter Roberson
el 5 de Mzo. de 2018
Create a new directory. Unzip the attached file into that directory. Inside MATLAB, cd to that directory. At the command line give the command
drive_a_tank
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!