error using sin or math.sin
댓글 수: 1
답변 (2개)
댓글 수: 0
Hi @Evone,
When working with mathematical functions in MATLAB, it is essential to understand the syntax and the appropriate functions available in the environment. The errors you are experiencing stem from a few key misunderstandings regarding function calls and the use of the math namespace, which is not applicable in MATLAB.
Understanding the Errors
Error: Unable to resolve the name 'math.sin' * In MATLAB, there is no math namespace as you might find in Python. Instead, trigonometric functions like sin, cos, and tan are directly available without any prefix.
Error: Not enough input arguments * This error occurs when the function is called incorrectly. In your case, you attempted to use sin* instead of sin(), which is the correct syntax for function calls in MATLAB.
Correcting the Code
To resolve these issues, you need to rewrite your equation using the correct MATLAB syntax. Below is the corrected version of your original expression:
result = (8 + 6) * abs(4 - 15) + sin(log10(18)) - (4 + 6) * tan(8 / 18 + 1);
Breakdown of the Corrected Code
- (8 + 6): This part calculates the sum of 8 and 6.
- abs(4 - 15): The abs function computes the absolute value of the difference between 4 and 15, which is 11.
- sin(log10(18)): The log10 function computes the base-10 logarithm of 18, and then sin computes the sine of that result.
- (4 + 6): This calculates the sum of 4 and 6, which equals 10.
- tan(8 / 18 + 1): This computes the tangent of the expression 8 / 18 + 1.
Final Result
To execute the code and obtain the final result, you can run the following complete MATLAB script:
% Calculate the result based on the provided expression result = (8 + 6) * abs(4 - 15) + sin(log10(18)) - (4 + 6) * tan(8 / 18 + 1);
% Display the result disp(result);
Please see attached.

By following the corrections outlined above, you should be able to run your MATLAB script without encountering the previous errors. Remember, always ensure that you are using the correct syntax for function calls in MATLAB, and avoid using namespaces that are not applicable in this environment. If you have any further questions or need additional assistance, feel free to ask!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!