title: Negative of a Number in MATLAB
body: <p>I have to make a function in MATLAB in which when input will be given, output will be the negative of that number. 
  The code that I wrote : </p>
  
  <pre><code>function [p] = negative(q)
  % given an input , output will be negative of that input
  
  w = subtract(0,1) ; 
  [p] = multiply(q,w) ;
  end
  </code></pre>
  
  <p>The code that I wrote for function subtract is : </p>
  
  <pre><code>function [m] = subtract(n,s)
  m = n ;
  while s
  [m]= decrement(m) ;
  s = decrement(s) ;
  end
  end
  </code></pre>
  
  <p>Code for multiply is : </p>
  
  <pre><code>function [a] = multiply(x,y)
  a = x ;
  y = decrement(y) ;
  while y
  [a]= addition(a,x);
  y = decrement(y);
  end
  end
  </code></pre>
  
  <p>Function for addition : </p>
  
  <pre><code> function [a] = addition(b,c)
   % adds b and c 
   a = b ;
   while c
   [a] = increment(a) ; 
    c = decrement(c) ;
   end
   end
  </code></pre>
  
  <p>Funtion increment code : </p>
  
  <pre><code> function out = increment(in)
   out = in + 1;
   end
  </code></pre>
  
  <p>Function decrement is following : </p>
  
  <pre><code>function out = decrement(in)
   out = in - 1;
  end
  </code></pre>
  
  <p>The code which I wrote for function negative should work according to me because I am multiplying the input with -1. But in MATLAB command window nothing is printed out (except w= -1) when I write negative(input) . Why is this and how shall I fix it ? 
  I am NOT allowed to use any operation including ( + , - , * , / , &lt; , > , ==) and neither am I allowed to use for loops. 
  Only thing I can use is assignment ( = ) and while loop. </p>