Info

This question is closed. Reopen it to edit or answer.

Error: Function definitions are not permitted in this context

1 view (last 30 days)
Please helps with this homework. I'm working on the one exercise and i keep coming up with an error.I've written my functions, and defined some variables to be plugged into them.
Write a function-file that can be used to calculate the equivalent resistance of n parallel connected resistors. In general, the equivalent resistance of resistors R1,R2,R3,Rn is given by:
1/Req=(1/R1)+(1/R2)+(1/R3)+....+(1/Rn)

Answers (1)

Geoff Hayes
Geoff Hayes on 7 Apr 2015
Carolina - typically the error message Function definitions are not permitted in this context occur because you have defined your function signature AFTER you have written some code. For example, if the test.m is defined as
a = 3;
function [b] = test(a)
b =2*a;
then I will observe the same error as you because I have defined the signature after at least one line of code.
When creating your function m file, the function signature can only be preceded by comments and not by code. Ensure that the signature is the first non-comment line in the file and try to run your function again.
Note that in the above, if I want to pass a into the function then I would do some from the Command Window as
>> a = 3; % initialize a
>> b = test(a); % call the function with a

Tags

Community Treasure Hunt

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

Start Hunting!