How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask LogicPro Your Own Question
LogicPro
LogicPro, Computer Software Engineer
Category: Programming
Satisfied Customers: 13075
Experience:  Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
29751445
Type Your Programming Question Here...
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: 3 years ago.
Category: Programming
Expert:  LogicPro replied 3 years ago.
Hi
Welcome here
My Name os logicpro and I will help you.
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.

Please bookmark my profile page:

http://www.justanswer.com/homework/expert-logicpro/

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 3 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 3 years ago.
I Also don't have the matlab program in my computer. However I have created the function in matlab file for you
Download example1.m
To call it, use
n= 4
example1(n)
n= 2
example1(n)
n= 10
example1(n)

it will show the result

Expert:  LogicPro replied 3 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.
Please bookmark my profile page:
http://www.justanswer.com/homework/expert-logicpro/
so you can come back and ask me a question anytime.
If you need any additional information on this answer, please don't hesitate to ask by clicking on 'Reply to Expert', and I will reply as soon as possible.
I hope you found the information in my answer helpful, and if so, please let me know, here. Thank you!
Thanks very much for using Just Answer!
Best wishes
LogicPro

Related Programming Questions