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...

  • Using Python: A Prime number is an integer greater than 1 that cannot be formed by...

    Using Python: A Prime number is an integer greater than 1 that cannot be formed by multiplying two smaller integer other than 1 and itself. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1. In this question you will write a program that takes a sequence of integers from the user and display all the prime numbers contained in that sequence. We will separate this question in...

  • 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...

  • 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,...

  • MATLAB Question: Write a script for the problem pictured. Please send the script, not just the...

    MATLAB Question: Write a script for the problem pictured. Please send the script, not just the printout. Make sure your script allows you to input a value for n so when prompted, in the command window, user types n value. The n value should be the f_k if k ==1 .... Please also send print outs if you can. BELOW IS A SAMPLE ANSWER THAT DID NOT PUT THE INPUT SCRIPT NEEDED FOR THIS QUESTION TO BE CORRECT. YOU CAN...

  • PLEASE HELP, MATLAB, answers are very appreciated need to study pl 2. Write two m-file functions...

    PLEASE HELP, MATLAB, answers are very appreciated need to study pl 2. Write two m-file functions that will allow you to compare mortgages cakculations for the monthly payment and compare mortgage with different loan values. The monthly payment M, is calculated using 1-2)1 Where Pis the principal loan amount, r is the interest rate (in decimal form not percent form), and y is the number of years of the loan. Create an m-file function called "mortgage_a.m" that will serve as...

  • Example program #include <string> #include <iostream> #include <cmath> #include <vector> using namespace std; vector<int> factor(int n)...

    Example program #include <string> #include <iostream> #include <cmath> #include <vector> using namespace std; vector<int> factor(int n) {     vector <int> v1;     // Print the number of 2s that divide n     while (n%2 == 0)     {         printf("%d ", 2);         n = n/2;         v1.push_back(2);     }     // n must be odd at this point. So we can skip     // one element (Note i = i +2)     for (int i = 3; i <=...

  • 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...

  • please there are some specific instructions on the question so i would greatly appreciate if they...

    please there are some specific instructions on the question so i would greatly appreciate if they are followed . thank you very much for your time This lab covers: arrays functions input exception handling Question 1 The purpose of this question is to write a python program (script) that manipulates arrays using vector arithmetic. You will compute the values of points The ellipse has a major axis whose length is a and a minor axis whose length is b. For...

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