Evaluating a function with Matlab
Mostrar comentarios más antiguos
Hello friends,
Can anyone help me figure out why I am getting an imaginary number in the following code:

I am supposed to get 1.36. I have done the same calculation using my scientific calculator and symbolab and cannot find what the error is in my code.
1 comentario
t = 10 ;
f = -((t-16.82)/5.604)^1.576
The result is clear, you are taking exponent of a negative number.
Respuesta aceptada
Más respuestas (1)
Then you have to program it as
t = 10;
f = sign(t-16.82).*abs((t-16.82)/5.604).^1.576
An expression
x^a
for x<0 is complex-valued.
1 comentario
Danny Guana
el 18 de Mayo de 2022
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!