Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Matlab // please with comments, Thanks a lot ^_^ ----------------------------

ID: 3666053 • Letter: I

Question

In Matlab // please with comments, Thanks a lot ^_^

------------------------------------------------------------------------------

Homework #1-First Script with MatLab (3 marks) After you learned how to form a script. Create a script that will calculate the net salary after deducting the taxes from the employee's salaries in the table below Employee Ahmed Zaina Noor 8000 22000 14000 Salary Rate Salary 10000 Tax Rate 5% 8% HINT: - Define Variables - Define the procedure Example: Deductapercentage from number Number 2000 Percentage-4% Result: 2000 0.04 80 2000-80-1920 - Place comments in script -Assign meaningful names to the variables This file should be sent to the instructors email within one week. Deadline: Tuesday 09/02/2016in the 4rd Week

Explanation / Answer

% - '%' is for commenting a line
% - disp() function used to display strings in single quotes, values if passed as param
% To clear previous output
clear

% INITIALIZATION: Names and Salary Vectors
% Just variablename will give you the output of vector. Ex: names
names = ['Ahmed' ; 'Zaina' ; 'Norr' ; ];
% names
% No semicolon at end will display content of vector - ; supresses the output, as in names vector.
salaries = [ 8000; 22000; 14000; ]
% OBSERVE IN LAST LINE WE OMITTED ; TO DISPLAY SALARIES VECTOR

% YOU CAN INCREASE SIZE IF REQUIRED
% names = ['Ahmed' ; 'Zaina' ; 'Norr' ; 'zakir'];
% salaries = [ 8000; 22000; 14000; 20000];

% FUNCTION DECLARATION
function netsalvalue=netsal(sal);
% Function declaration with salary as parameter
% We will decide tax percentage based on salary
if sal<=10000
netsalvalue=sal-(sal*0.05);
else
netsalvalue=sal-(sal*0.08);
end
end

% Main program:

% Calc vector size
[col,row]=size(salaries);

% Verify given vector is not empty
if row<1 || col<1
disp('Error in input');
end

% Loop to iterate through the number of employees
for i=1:col
disp('Salary of ');
disp(names(i,:));
disp('is = ')
disp(salaries(i));
netsalvalue=netsal(salaries(i));
disp('Net salary is = ');
disp(netsalvalue);
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote