- "function" is spelled incorrectly which I'm sure is a typo.
- What is x? Is it a scalar (single value) or a vector/matrix/array? If it's not a scalar, then no, this is not correct.
- While x*x is effectively squaring a scalar, why not square the value using an exponent?
- This is minor, but stylistically, there's no need for the space between sqr and (x).
- Instead of asking if it's correct, test it!! Provide a wide variety of inputs including large numbers, small numbers, negative numbers, 0, etc.
Write a MATLAB function that returns the square of a number.
23 views (last 30 days)
Show older comments
funciton square = sqr (x)
square = x * x;
end
Is it correct ?
0 Comments
Answers (1)
Adam Danz
on 14 Mar 2021
Edited: Adam Danz
on 14 Mar 2021
> Is it correct ?
funciton square = sqr (x)
square = x * x;
end
Feedback
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!