function for m file
Show older comments
I was given the function:
g(x,y) = (x^2/y^4)+(cos(7*x*exp(9*y))/(x^6 + 2));
and was instructed to format it as an anonymous function:
g = @(x,y) (x^2/y^4)+(cos(7*x*exp(9*y))/(x^6 + 2));
When trying to create the m file, the contents were written as:
g = @(x,y) (x^2/y^4)+(cos(7*x*exp(9*y))/(x^6 + 2
function g = f(x,y)
g = (x^2/y^4)+(cos(7*x*exp(9*y))/(x^6 + 2));
end
When then trying to run the file, this error appears:
Error: File: g.m Line: 1 Column: 1
Using 'g' as both the name of a variable and the name of a script is not supported.
The file is to be named g.m and be called using g(x,y), x and y being any number, as per assignment instructions. What is causing the file not to run?
1 Comment
"What is causing the file not to run?"
The error message already tells you exactly what the problem is. Lets read it:
"Using 'g' as both the name of a variable and the name of a script is not supported."
Lets look at the information you gave about the script name:
"The file is to be named g.m ..."
Lets look at the information you gave about the variable name:
function g = f(..)
g = (..);
end
So you clearly used g for both the filename as well as the name of a variable. Which the error message clearly states is not allowed. If the error message unclear, how could it be improved?
Accepted Answer
More Answers (0)
Categories
Find more on Debugging and Analysis 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!