Question
mathlab please copy and paste the code and output
Q1. (50 points) Consider the following mathematical sequence for any mumber fathe sequence, the first number is 1 = 0. The re
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below are the code in MATLAB for the above question:

************************************ 1(a) ************************************
% function sequence1 to find sequence
% upto 10 terms.
function x = sequence1(a)
% assigning x(0) to a.
x = a;
% now finding upto 10 terms using
% given condition.
for i = 2:10
% if previous element is even
if(mod(x(i-1),2)==0)
x(i) = x(i-1)/2;
% if previous element is odd
else
x(i) = 3*x(i-1)+1;
end
end
end

************************************ 1(b) ************************************
function x = sequence2(a)
% assigning x(0) to a.
x = a;
% now finding ten terms using
% given terms.
i = 2;
while(1)
% first cheking if previous element is
% 1 or not
if(x(i-1)==1)
break;
end
  
% if previous element is even
if(mod(x(i-1),2)==0)
x(i) = x(i-1)/2;
% if previous element is odd
else
x(i) = 3*x(i-1)+1;
end
i = i + 1;
end
end

************************************ 1(c) ************************************
function s = sequence3(a)
% assigning x(0) to a.
x = a;
% now finding ten terms using
% given terms.
i = 2;
% finding element of sequence
while(1)
% first cheking if previous element is
% 1 or not
if(x(i-1)==1)
break;
end
  
% if previous element is even
if(mod(x(i-1),2)==0)
x(i) = x(i-1)/2;
% if previous element is odd
else
x(i) = 3*x(i-1)+1;
end
i = i + 1;
end
% storing size of vector x before it hits 1.
s = length(x)-1;
end

CODES IN LIVESCRIPT:

% test for 1(a)
sequence1(27)

% test for 1(b)
sequence2(19)

% test for 1(c)
S = zeros(1,100);
A = zeros(1,100);
% loop to find sequence length
% range from 1 to 100.
for i = 1:100
% storing i to A
A(i) = i;
% storing length of sequence
% before it hits 1 to vector S.
S(i) = sequence3(i);
end
% plotting A vs S.
plot(A,S);

Refer to the screenshot attached below to better understand the code and indentation:

************************************ 1(a) ************************************
function sequencel to find sequence $upto 10 terms. function x = sequencel (a) $ assigning x(0) to a. - 56GBEE coonWN II $now

************************************ 1(b) ************************************
function x = sequence2 (a) assigning x(0) to a. x = a; now finding ten terms using $ given terms. i = 2; while (1) first chek

************************************ 1(c) ************************************
function s = sequence3 (a) assigning x(0) to a. I now finding ten terms using $ given terms. i = 2; finding element of sequen

Output:

sequencel(27) ans = 1x10 double 27 82 41 124 62 31 94 47 142 71 sequence2 (19) ans = 1x21 double 1958 2988 44 22 11 34 17 52

S = zeros(1,100); A = zeros(1,100); % loop to find sequence length % range from 1 to 100. for i = 1:100 % storing i to A A(i)
о o 10 20 30 40 50 60 70 80 90 100

If this answer helps you then please upvote,
for further queries comment below.

Thank you.

Add a comment
Know the answer?
Add Answer to:
mathlab please copy and paste the code and output Q1. (50 points) Consider the following mathematical...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A code in matlab. (maybe Jammer can answer)? Consider the following income tax brackets. Income ($)...

    A code in matlab. (maybe Jammer can answer)? Consider the following income tax brackets. Income ($) 0 - 10,000 10,000 - 25,000 Tax 0% 5% on amount exceeding 10,000 $750 + 8% on amount exceeding 25,000 $2,750 + 10% on amount exceeding 50,000 $7,750 + 15% on amount exceeding 100,000 $67,750 + 25% on amount exceeding 500,000 25,000 - 50.000 50,000-100,000 100,000-500,000 > 500,000 250 Thus, if the income is $70,000, then the fourth bracket will apply and the tax...

  • I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a...

    I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a program that uses a for loop to calculate a Fibonacci sequence (NOT RECURSIVE!!!) up to a given position, starting with position 0. This function defines a Fibonacci sequence: If the number is 0, the function returns a 0 If the number is 1, the function returns a 1 If the number is higher than 1, it returns the sum of the previous two numbers...

  • Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a....

    Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a. Write the following as script6.sh and change its permissions to count for num in d do if num eq 100 then count (count+1) done echo The number 10 was found $count times What is the output? Run the script as ./script6.sh 10 20 30 10 40 20 50 10 60 <enter Summarize what the script does r using the read command. The following script...

  • This code should be in C please!! Your file should meet the following criteria: • Function...

    This code should be in C please!! Your file should meet the following criteria: • Function prototype and implementation for a calculateDivisors function that takes in an integer parameter, calculates the sum of its divisors, and returns that sum (as an integer value) • A structure that represents what is represented on each line of output, e.g., o Line number o Sum of the divisors for that line number o Character array containing “Perfect”, “Deficient”, or “Abundant” • Pointer declared...

  • Write a code using loop and flag function in python jupitior notebook: Ask the user for...

    Write a code using loop and flag function in python jupitior notebook: Ask the user for the number of items they bought. Also ask the price of each item they bought and quantity purchased. Display the total amount they owe. Ask the user for a number n. Calculate 1+2+3+….+n. Ask the user for a number n. Calculate 1*2*3*…*n. Ask the user for number of rows (r) and columns (c). Print * for r rows and c columns. Ask the user...

  • PLEASE USE ECLIPSE AND INCLUDE A READABLE COPY OF YOUR OUTPUT FOR THE FOLLOWING PROBLEM. IT...

    PLEASE USE ECLIPSE AND INCLUDE A READABLE COPY OF YOUR OUTPUT FOR THE FOLLOWING PROBLEM. IT IS VERY IMPORTANT TO USE ECLIPSE AND NOT SOMETHING ELSE TO WRITE THE REQUIRED C++ PROGRAM. THANK YOU. Design Specifications: Write a C++ function named inches_ to centimeters (). This function accepts one variable of type float that represents the value of inches, and returns one variable of type float that represents the equivalent number of centimeters. Use the relationship that 1 inch 2.54...

  • this is c++ and please let the code works on vs2017. the output should be same...

    this is c++ and please let the code works on vs2017. the output should be same as the question. mes A. Hotz Programming Challenge: Prime qumber Array Values from Canvas: ICE12A Please name your source file: PC7101.CPP A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5 The number 6, however, is not prime because it can...

  • w Problem Statement: In mathematics, a series is, roughly speaking, a description of the operation of...

    w Problem Statement: In mathematics, a series is, roughly speaking, a description of the operation of adding infinitely many quantities, one after the other, to a given starting quantity. The study of series is a major part of calculus and its generalization, mathematical analysis. Mathematically, the n" number of a mathematical series is defined as follows: T. -Σ . . Write a CH program that: Reads a positive integer k from the user. If the user enters a negative value,...

  • Solve the following problem in MATLAB. Use format compact for all work to suppress extra lines....

    Solve the following problem in MATLAB. Use format compact for all work to suppress extra lines. Show all work and add comments as needed to explain your logic/steps. 1. The function f(x) = e* can be approximated by the following Taylor series: n=0 The first few terms of the Taylor series are: e 1 + x + + + + ...... 2! 3! 4! Keep in mind that the "!" symbol denotes factorial. For example, the factorial of 4 =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT