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

By using matlab, 1, Write a function that accepts a single input integer and det

ID: 3028316 • Letter: B

Question

By using matlab,

1,  Write a function that accepts a single input integer and determines if the input integer is prime. It should display a message that is appropriate.

2, Simple and compound interest: write a function that accepts three inputs: the initial principal (P), the annual interest rate (R) and total time of deposit (T). Your function should appropriately display the simple interest (calculated as P*R*T) as well as the compound interest, for the time specified. Calculate the compound interest using a loop in your code -- DO NOT use the compound interest formula.

Explanation / Answer

1.)

function output = is_prime(number)

output=1;

%% output is 1 if it is a prime and 0 for not a prime.

%% check if number is a nonnegative integer
if floor(number)~=number || number<0
output=0;
return
end

%% check if number can be divided by another integer
for k=2:(number/2)
if rem(number,k)==0
output=0;
return
end
end

end

2.)

Matlab Code:

function [SI, CI]=interest(P,R,T)

%% SI = Simpli Interest

SI=P*R*T;

%% CI = Compound Interest

%% T is a time period in years or months for which R is defined.

CI=P;

for i=1:T
CI=CI+(R*CI);
end

CI=CI-P;

end