Damped Cosine wave not working
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Nicholas Gresham
el 22 de Mzo. de 2020
Respondida: Sriram Tadavarty
el 22 de Mzo. de 2020
function dampedOsc3()
x = (0:0.01:4);
y = @(x)(exp.^(-0.4.*x))*cos(5.*x);
plot(x,y,'--c')
end
Why is this Code not working, matlab is saying that there is an error with the final line " plot(x,y,'--c') "
0 comentarios
Respuesta aceptada
Sriram Tadavarty
el 22 de Mzo. de 2020
Hi Nicholas,
The usage of function handle is wrong here. If you want it to be a function handle, you need to pass input to y. But, this is not passed.
The next issue is exponential is not written properly.
Here are few suggestions to the code that make it work:
x = (0:0.01:4);
y = exp(-0.4.*x).*cos(5.*x); % Need not have function handle and then directly exp (), no need of ^
plot(x,y,'--c')
% If you want use it with function handle itself, here is the way it can be done
x = (0:0.01:4);
y = @(x) (exp((-0.4.*x))).*cos(5.*x); % Place exponential properly
plot(x,y(x),'--c') % Pass x here
Hope this helps.
Regards,
Sriram
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!