1

Implementing this MATLAB function

function y=myfunc(x)
    y=x^2+5*x+6;
end

is resulting in the following error.

>>myfunc(5)
Undefined function 'myfunc' for input arguments of type 'double'

I'm new to MATLAB, and any help would be appreciated!

3
  • 1
    It's probably wither in a file that is not called "myfunc.m" or not in the same folder where you are Commented Apr 18, 2021 at 12:10
  • mathworks.com/help/matlab/matlab_prog/… Commented Apr 18, 2021 at 15:07
  • Please edit your question to clarify where you put that function definition. Commented Apr 18, 2021 at 15:08

1 Answer 1

0

You can get results by two methods in matlab

  1. call function and define function below
answer= myfunc(5)

function y=myfunc(x)

y=(x^2)+(5*x)+6;

end
  1. a) Second option is to make a new function file but name of function and file name should be same

so make a file name as myfunc and write you function code there

function y=myfunc(x)

y=(x^2)+(5*x)+6;

end
  • b) in separate file with any name you can call that function

answer= myfunc(5)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.