MATLAB: Cumulative If Loop question

homeworkif elseif statement

I am trying to write a function that expresses the tax rate. For example, for an income of $40,000, the first $35,350 is taxed at 15%. The remaining $4,650 is taxed at 28%. I am not quite sure how to express this. I have this code written up, but it only shows the tax rate for a specific income, but it doesn't calculate the difference between the first and the second tax rate and account for the difference in the tax rate. How do i go about fixing this?

Best Answer

elseif 35350 <= income & income < 85660
taxrate= .28
taxpaid= (taxrate .* income) + income
The math part of this should read something like
taxpaid = 0.15*35350+0.28*(income-35350);
%Apply 15% to the 35359 and 28% to the remainder
Now you can take all of those fixed values and turn them into vectors that could be traversed with a for-loop or fancy multiplication
taxrate = [0.15 0.28 0.31 0.396];
taxlim = [35350 etc.]