2.Write MATLAB programs using while loops to do the following. Although you will
ID: 3631553 • Letter: 2
Question
2.Write MATLAB programs using while loops to do the following. Although you will probably see ways to solve these problems without iteration, you must use it for all these solutions.(a) Display numbers from 1,2,3...till the user-defined max value N=50.
(b) Display numbers from 50, 49, 48,...as long as all are positive numbers.
(c) Display only even numbers from 2,4,6,...till the user-defined max value of N=50.
(d) Create a vector x with odd numbers 1,3,5,...till the user-defined max value of N=99.
(e) Create a vector y with its elements as cube of its indices: 1,8,27,...till the user- defined max value of 1000000.
Explanation / Answer
clear;clc %% part a n = input('please enter a number: '); i = 1; while i 0 fprintf('%d ',i); i = i - 1; end fprintf(' '); %% part c n = input('please enter a number: '); i = 2; while iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.