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

Midnight. Upload one function, function lastname_howmework5 () in a single m-fil

ID: 3674655 • Letter: M

Question

Midnight. Upload one function, function lastname_howmework5 () in a single m-file that runs each problem along with all of the sub-functions or nested -functions that work that particular problem. When your function, lastname_homowork5 is typed into the command window, the homework problems should run sequentially showing plots and the required proof that each sub-function works correctly. Place any required answers in comments above the sub-function implementation. There will be a loss of 10 points for not following these directions exactly. Implement the following equation in a function, value = problem_1 (N). Plot for N = 1-500. What value does the series converge to as N rightarrow infinity? Implement the following equation in a function, value = problem_2 (N). Plot for N = 1-500. What value does the series converge to as N -rightarrow infinity? Implement the following equation in a function, value = probiem_3 (N). Plot for N = - 500. What value does the series converge to as N rightarrow infinity? Implement the following equation in a function, value = probiem_4(x, N). Plot for N = 1-50. What value does the series converge to as N rightarrow infinity for the values of x = 1/2, 1/3, and 1/5? Implement the following equation in a function, value = problem_5 (N). Plot for N = 1-500. What value does the product converge to as N rightarrow infinity?

Explanation / Answer

function problem1() {

    var sum = 0;

    for (var i = 0; i < sum; i++){

    if((i % 3 === 0) || (i % 5 === 0)){

        sum += i;

    };

}

<div class = "problem1">

      <h4>Problem 1: Multiples of 3 and 5</h4>

      <p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.</p>

      <p>Find the sum of all the multiples of 3 or 5 below <b>1000.</b></p>

      <input id = "input" type = "text" value ="1000"></input>

      <button>Solve</button>

      <div id = "result"></div>

</div>

Here is a jsfiddle to show what I'm working with: http://jsfiddle.net/wh9uj2j6/1/

Answers :

function problem1() {

    var sum = 0;

    for (var i = 0; i < sum; i++){ //This loop will never run since sum == 0

    if((i % 3 === 0) || (i % 5 === 0)){

        sum += i;

    };

    //nothing is returned.

}

Other problems: showResult() isn't a function, getElementById('input').innerHTML should be getElementById('input').value.

I think what you wanted to do is:

function problem1(num) {

    var sum = 0;

    for (var i = 0; i < num; i++)

    {

        if((i % 3 === 0) || (i % 5 === 0))

        {

            sum += i;

        }

    }

    return sum;

}

<div class = "problem1">

      <h4>Problem 1: Multiples of 3 and 5</h4>

      <p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.</p>

      <p>Find the sum of all the multiples of 3 or 5 below <b>1000.</b></p>

      <input id = "input" type = "text" value ="1000"></input>

      <button>Solve</button>

    <div id = "result"></div>

</div>

Exactly what I was looking for. Thank you!

Why the downvote, though?

0

Your entire javascript function makes no sense, try this instead:

function solve() {

    var sum = 0; // result var

    var input = document.getElementById('input').value; // input for iteration

    for(var i = 0; i < input; i++) {

        if((i % 3 === 0) || (i % 5 === 0)) {

           sum += i;

        }

    }

    document.getElementById('result').innerHTML = sum; // print result in div

}

<?include 'include/connect.php';

    $max_number = max(count($_POST["feel"]), count($_POST["problem"]));

    for($i=0; $i < $max_number; $i++)

    {

    $array=array(

        "self_assessment_emotion"=>$_POST['feel'][$i],

        "self_assessment_physical"=>$_POST['problem'][$i]

    );

    $feel_problem = $db_obj->insert($array,"tbl_self_assessment");

    }

    ?>

function problem1() {

    var sum = 0;

    for (var i = 0; i < sum; i++){ //This loop will never run since sum == 0

    if((i % 3 === 0) || (i % 5 === 0)){

        sum += i;

    };

    //nothing is returned.

}

Other problems: showResult() isn't a function, getElementById('input').innerHTML should be getElementById('input').value.

I think what you wanted to do is:

function problem1(num) {

    var sum = 0;

    for (var i = 0; i < num; i++)

    {

        if((i % 3 === 0) || (i % 5 === 0))

        {

            sum += i;

        }

    }

    return sum;

}

<div class = "problem1">

      <h4>Problem 1: Multiples of 3 and 5</h4>

      <p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.</p>

      <p>Find the sum of all the multiples of 3 or 5 below <b>1000.</b></p>

      <input id = "input" type = "text" value ="1000"></input>

      <button>Solve</button>

    <div id = "result"></div>

</div>

Exactly what I was looking for. Thank you!

Why the downvote, though?

0

Your entire javascript function makes no sense, try this instead:

function solve() {

    var sum = 0; // result var

    var input = document.getElementById('input').value; // input for iteration

    for(var i = 0; i < input; i++) {

        if((i % 3 === 0) || (i % 5 === 0)) {

           sum += i;

        }

    }

    document.getElementById('result').innerHTML = sum; // print result in div

}