i need help with this?
Mostrar comentarios más antiguos
Consider the function defined by g(x) =sin(πx), x ∈ (−1, 1] x^4 − 1, x ∈ [−1.5, −1] ∪ (1, 1.5] (a) Write a MATLAB function gxsin that takes as input a vector x, and returns a vector y that contains the corresponding values of the function g. (b) Using the function gxsin and a suitable array x containing 102 entries, write appropriate MATLAB commands that produce a plot of the function defoned above. The plot should be entitled "Plot of g(x) vs x". THIS IS WHAT I HAVE:
function y = gxsin(x)
for i=1:length(x)
if (x(i)> -1) && (x(i)<=1)
g(i)=sin(pi*x(i));
elseif (x(i)>=-1.5) && (x(i)<=-1)|| (x(i)>1) && (x(i)<=1.5)
g(i)= ((x.^4 -1));
end
end
end
x=linspace(-1.5,1.5,102);
y=gsxin(x), I'm getting an error when i type this part
1 comentario
Torsten
el 12 de Nov. de 2018
You see the error in the line
g(i)= ((x.^4 -1));
?
Respuesta aceptada
Más respuestas (0)
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!