i need help with this?
Show older comments
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 Comment
Torsten
on 12 Nov 2018
You see the error in the line
g(i)= ((x.^4 -1));
?
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!