MATLAB Answers

Error: File: Lab1.m Line: 81 Column: 1 Function definitions in a script must appear at the end of the file. Move all statements after the "f" function definition to before the first local function definition.

19 views (last 30 days)
Qais AlAttar
Qais AlAttar on 11 Sep 2020
Answered: Cris LaPierre on 11 Sep 2020
% Question 6:
% a)
g=@(x,y)(x.^4./y.^2)+cos(3*x.*exp(2*y))./(x.^5+6);
g(-7,-1)
% b
clear g
save(g.m)
function z=g(x,y)
z=(x^4/y^2)+cos(3*x*exp(2*y))/(x^5+6);
g(-7,-1)
end

  0 Comments

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 11 Sep 2020
What you have shared looks good, but you have not shared your full file (we do not see 81 lines, nor do we see a function f). As the error message states, and declared functions must be at the very bottom of your live script. I suspect there is at least a Question 7 that you have not included, meaning function z is not the last thing in your file.
See this documentation page for more on local functions.

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!