Governing Equations

Governing Equations

Logical Operators

  • we explored two cases where we could use logical operators/structures (logical vectors) to
    handle
    • The logical vectors would “turn on” (return a “1”) under some conditions and “turn off” for others.
    • These programs are included to help you model things for this project

Objectives

  • Solve the following problem statement with if-else ladders
    • Solve the same problem statement again with logical vectors (structures) instead (INSTEAD) of if-else ladders
    • Test each case by displaying the correct values for thefollowing incomes: $5,000, $10,000, $11,000, $15,000, $30,000 and $100,000
    (your income after graduation)
    • Publish your results as a PDF

Problem Statement

  • The IRS has a tax table given as …
    • Taxable Income $10,000 or less …. tax is 10% of taxable income
    • Taxable income between $10,000 and $20,000 …
    $1,000 + 20% of the amount by which the taxable income exceeds $10,000
    • Taxable income more than $20,000 … $3,000 + 50% of the amount by which the taxable income exceeds $20,000

LogicGames_Sinx_Corrected.m

 %% Title – Sinc(x) Challenge Problem

%% Governing Equations

%  y (x)  = sin (x)   /  x

%  range = -4pi to + 4pi

%%  Set range vector

lowerlim = -4 * pi ;

upperlim = 4 * pi  ;

x = lowerlim :  pi/20 : upperlim   ;

%  Nudge any zero values by the smallest number possible

x = x + (x == 0) * 1E-20 ;

% Matlab also has a function for that (eps)

%x = x + (x == 0) * eps;

%%  Determine y for each x

y = sin(x) ./ x   ;             % ./ so that we go element-by-element

%%  Plot Results

plot (x,y)

LogicGames_Tan_Corrected.m

 %% Title

%% Governing Equations

%  y (x)  = tan(x)

%  range = -3pi/2 to + 3pi/2

%%  Set range vector

lowerlim = (-3/2) * pi ;

upperlim = (3/2) * pi  ;

x = lowerlim :  pi/100 : upperlim   ;

%%  Determine y for each x

y = tan(x)   ;

%%  Remove values which are INSANELY large

y = y .* (abs(y) < 1e10) ;    % (…) equals 1 if reasonable, 0 if huge

%%  Plot Results

plot (x,y) 

Solution

Program with MATLAB using if-else ladder: 

clearall

clc

x=[5000 10000 11000 15000 30000 100000];%Incomes taxables

i=1;

while i<=length(x)

if x(i)<=10000% first condition

tax(i)=0.1*x(i);

elseif x(i)>10000&&x(i)<20000% Second condition

tax(i)=1000+0.2*x(i);

else x(i)>20000% Third condition

tax(i)=3000+0.5*x(i);

i=i+1;

end

end

H1={‘incomes taxable’,’output tax’};%Titles of the table

H=[x’ tax’];% Results

HH=[H1;num2cell(H)]% Table complete

Output:

‘incomes taxable’    ‘output tax’

[           5000]    [       500]

[          10000]    [      1000]

[          11000]    [      3200]

[          15000]    [      4000]

[          30000]    [     18000]

[         100000]    [     53000]

Program with MATLAB using logical vector with if-else ladders:

clearall

clc

x=[5000 10000 11000 15000 30000 100000];%Incomes taxables

i=1;

while i<=length(x)

X1=(x(i)<=10000)

if X1(i)==1

tax(i)=0.1*x(i);

else

end

X1=(x(i)>10000)&&(x(i)<20000)

if X1==1

tax(i)=1000+0.2*x(i);

else

end

X1=(x(i)>20000)

if X1==1

tax(i)=3000+0.5*x(i);

else

end

i=i+1;

end

H1={‘incomes taxable’,’output tax’};%Titles of the table

H=[x’ tax’];% Results

HH=[H1;num2cell(H)];% Table complete

Output:

‘incomes taxable’    ‘output tax’

[           5000]    [       500]

[          10000]    [      1000]

[          11000]    [      3200]

[          15000]    [      4000]

[          30000]    [     18000]

[         100000]    [     53000]