can anyone help me solve these two questions please?

1.Write a MATLAB program to find the value of f(x) is -2x when x < 0; x(x-2) when x is in [0, 2] and log(x-1) otherwise.
2. write a MATLAB program to find out the sum of the first 10 numbers in fribonacci series.
TIA

Answers (2)

1)
F=(x<0)*(-2*x)+(x<=2)*(x>=0)*(x*(x-2))+(x>2)*(log(x-1));
2)
Y=sum(fibonacci(1:10));

8 Comments

Answering a homework question with a full solution is strongly discouraged in this forum.
Please don't do homework assignments for people. It does not help them, nor does it teach them anything but that a sucker is to be found here who will do my homework for me.
Try to use this rule - the more the student has made an effort of their own, the more you can be willing to help them. For example, if a student shows the problem, then shows that they tried, and you can see they were totally correct in that they did, except for a minor bug? Then just show them how to fix it. They knew what to do, and how to solve the problem already, and they were forthcoming with their attempt. Essentially, this student is interested in learning, and they can benefit from what you show them.
An example is if a student has the correct code, but does not understand the difference between the * and .* operators? Now you can explain that difference, and show where the .* operator is necessary.
But suppose the student shows code that is haphazard, not at all on-target to solve the problem (but at least shows code)? Now you want to point them in a reasonable direction. Perhaps suggest they look at some functions that will help them to solve their problem. But don't write the code for that student. You might suggest they take the Onramp tutorial, if they seem to have no real clue about coding, but at least made an attempt.
For example, just recently, I spent roughly an hour writing up a lengthy description of how to find a function that will solve a problem, using the help tools in MATLAB. This was for a student who seemed to care about learning.
Last, suppose a student does nothing but post a picture of their homework assignment, and demand help soon with no effort shown, because their homework is due in a few hours? Oh, thats right, I probably closed that question already, before you even saw it. :) This student has no interest in learning, just in a grade on their homework.
Essentially, the more effort a student puts in, the more you can help them. I've seen students who show a real interest in what they see, coming back with interesting followup questions. That is the student who I truly respect and enjoy helping.
Sure I'll follow this,thank you.
It's not like I don't have any ineterest in learning. I have my own reason for asking these questions. Thank you for answering my questions.
And to those who got butthurted just because someone answered my questions, I am sorry.
@rsn - If you want help here, then you need to show some effort. Otherwise, you have shown no more interest than someone who wants nothing more than to get their homework answered.

Sign in to comment.

help fibonacci
FIBONACCI Symbolic Fibonacci numbers. F = FIBONACCI(N) returns the N-th Fibonacci number. If N is a nonnegative integer then FIBONACCI(N) returns the N-th Fibonacci number. FIBONACCI(N) returns an error if the argument evaluates to a number of wrong type. FIBONACCI(N) returns the unevaluated function call if N does not evaluate to a number. Documentation for fibonacci doc fibonacci Other functions named fibonacci sym/fibonacci

Categories

Find more on Programming in Help Center and File Exchange

Asked:

rsn
on 6 Nov 2020

Commented:

on 7 Nov 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!