i need help with this?
Afficher commentaires plus anciens
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 commentaire
Torsten
le 12 Nov 2018
You see the error in the line
g(i)= ((x.^4 -1));
?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!