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 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 5 Mar 2018
Edited: Walter Roberson
on 5 Mar 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 Comments
Walter Roberson
on 5 Mar 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
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!