error using sin or math.sin

11 visualizaciones (últimos 30 días)
Evone
Evone el 12 de En. de 2025
Respondida: Umar el 13 de En. de 2025
I have plugged in math.sin and sin into my equation and I continue getting errors when trying to run the script. I am lost and I am not sure how to correct this.
(8+6)*abs(4-15) + math.sin(math.log10(18))-(4+6) * math.tan(8/18+1)
Unable to resolve the name 'math.sin'.
(8+6)*abs(4-15) + sin*(math.log10(18))-(4+6) * math.tan(8/18+1)
Error using sin. Not enough input arguments.
  1 comentario
Stephen23
Stephen23 el 12 de En. de 2025
Editada: Stephen23 el 12 de En. de 2025
It looks like Python:
In any case:
(8+6)*abs(4-15) + sin*(math.log10(18))-(4+6) * math.tan(8/18+1)
% ^ what do you expect this asterisk to achieve?

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 12 de En. de 2025
(8+6)*abs(4-15) + sin(log10(18))-(4+6) * tan(8/18+1)
ans = 76.2282
math.sin looks like syntax for Python.

Umar
Umar el 13 de En. de 2025

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!

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by