Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Quick matlab question regarding if statements/for loops
I need to write a code for if x>a then calculate (x-a)^n, if x<=a output 0. I figure my initial issues were that since x can be scalar OR VECTOR then i had to adapt the code for that. I am having issues picking each element from vector x.
My code so far
x=input('enter "x" as a vector [a b] or variable: ');
n=input('enter "n" parameter: ');
a=input('enter "a" parameter: ');
I get 27. Which is just the correct answer for 5. When x=0 it should be giving me 0 obviously which it is not.
Added attachment of the piecewise function I am trying to make.
0 · ·