• 100% Satisfaction Guarantee
LogicPro, Computer Software Engineer
Category: Programming
Satisfied Customers: 13296
Experience:  Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
29751445
LogicPro is online now

# Understand and explain the following function. Try to get the

### Customer Question

Understand and explain the following function. Try to get the values of A when
1), n=4;
2), n=2;
3), n=10;

%%%%%%%%%%%%%%%%
function s=example1(n)
a=3;
if n<=5
A=a^(n);
elseif n<=10
A=a/n;
else
A=a+31;
end
A
%%%%%%%%%%%%%%%%
Submitted: 4 years ago.
Category: Programming
Expert:  LogicPro replied 4 years ago.
Hi
Welcome here
1), n=4; then A is 81
2), n=2; then A is 9
3), n=10; then A is 0.3

Proof:
If n = 4 then following if condition will be true:
if n<=5
Since a is 3, 3 will be raised to the power 4 and result will be stored in A
so A = 3 ^ 4 = 81

If n = 2 then following if condition will be true:
if n<=5
Since a is 3, 3 will be raised to the power 2 and result will be stored in A
so A = 3 ^ 2= 9

If n = 10 then following if condition will be true:
elseif n<=10
Since a is 3, 3 will be devided by 10 and result will be stored in A
so A = 3 / 10 = 0.3 (rounded off)

You can ask me again using "For LogicPro only" at the start of your questions like other customers to get instant answers.

It will ensure that question is for me.

so you can come back and ask me a question anytime.

Remember, if for any reason you are unsatisfied with my answer, we can continue the conversation until you’re satisfied and rate my answer as excellent. I can address follow up questions on original requirements at no extra charge and I’m always here to help.

Thank you for using this site!

Customer: replied 4 years ago.

hi

I wanted to know how to write it exactly in matlab program and I don't have the matlab program in my computer so I need you to solve it in matlab and copy what you typed thanks

Expert:  LogicPro replied 4 years ago.
I Also don't have the matlab program in my computer. However I have created the function in matlab file for you
To call it, use
n= 4
example1(n)
n= 2
example1(n)
n= 10
example1(n)

it will show the result

Expert:  LogicPro replied 4 years ago.
Hi again,
Just following up with you to see how everything is going and if you have more questions for me.
You can ask me again using "For LogicPro only" at the start of your questions like you do to get instant answers.
It will ensure that question is for me.