Anyone here familiar/good at matlab programming?
Yes.
Im trying to do some basic if else, and need someone to take a peek at my code.
function [] = JohnsonJHW7 () % Johnson, Jason R. % ENGR 102- Angela Martinek % February 23rd 2014 % HW 7, Chap 8-9 clear, clc disp('Jason Johnson') disp('Homework 7') disp('February 27th, 2014') disp('Problem 8.6') disp('Create a function called g that satisfies the following criteria:') disp('For x < -pi g(x) = -1') disp('For x >= -pi and x<= pi g(x) = cos(x)') disp('For x > pi g(x) = -1') x = [-2*pi:.1:2*pi]; plot(x, piecewise(x)) title('Graph of Piece wise Function g(x)') xlabel('X') ylabel('Y, g(x)') end function result = piecewise(x) % This function requires a scalar input. if (x<-pi) result = -1; elseif(x<=pi) results = cos(x); else(x<2*pi) result = -1; end end
@doc.brown
Are you looking for a scalar input on the result?
I think that is part of my problem. I want to put in a vector as input....and I want it to basically graph the output as a vector also so I can plot x from -2pi to 2pi and have it plot a piecewise function where values from -2p to - pi are == -1, values >= - pi and x<= pi - cos(x), and x>pi = =1.
Join our real-time social learning platform and learn together with your friends!