Given code:
clc;
clear;
t=0:1:10;
y = cos(t);
y
output:
Using for loop:
clc;
clear;
y = []; %empty vector to store cosine values.
for t=1:11 %it will run 1 to 11 so run 11 times.
y(t) = cos(t-1); %calculating consine values 0 to 10 and strong in
vector.
endfor
%printing the cosine values.
disp("Using for loop: ")
y
output:
Using while loop:
clc;
clear;
y = []; %empty vector to store cosine values.
t=1; %staring with 1 because vector index starts with 1.
while t<=11 %up to 11 ie. it will run 11 times.
y(t) = cos(t-1); %calculating cosine value 0 to 10 and storinng in
vector.
t += 1; %increaseing the t value.
endwhile
%printing the consine values.
disp("Using while loop: ")
y
output:
Note: my friend if you have any questions or queies comment below. I am happy to answer your all questions. i will sort out your queries. Thank you my friend.
Ql. The following MATLAB code computes the cosine value ranging from 0 to 10 using vectorization...
In MATLAB The value of cos(x) can be approximated using a Maclaurin series + +... cos(x)=1-1 2! 4! 6! Which can be expressed compactly as cos(x) = {(-1)+7 (2(k-1))! 00 2(k-1) k-1 Write Matlab code using a while loop that calculates cos(2) with 5 terms of Maclaurin series. Compare the value with the one calculated with a built-in function cos (2) in Matlab. The following is an expected output from your code: Using the Maclaurin series cos( 2.0) with 5...
Using matlab, write the code and plot the graph for the following equations. The x axis would be theta from 0 deg to 360 deg while the y axis would be angular or tangential position, velocity and acceleration. 10 100 E7360 AB- eD100mm sin 1O-Sn 2To ne cose, t Cas 2 3 4 O,= To (reano,re bease-feo, sene-Feo 6 as ) Cos O2 10 100 E7360 AB- eD100mm sin 1O-Sn 2To ne cose, t Cas 2 3 4 O,= To...
For questions 10-12, refer to the following iterative code computes values for the table t. 1 public int [] tIterative (int [C A)1 2 3 4 int n - A.length; int [] t = new int [n]; int j; for (inti-0; i 0) while (j > 0 && A[j] [1] A[i] [O]) 12 13 14 15 16 t[i]Math.max( t[i-1] , A[i][i] - A[i] [o] + t[j] ); return t; 10. Does the code for tIterative use dynamic programming? 11. What...
THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that calculates exp(2) by a Maclaurin series using a while loop exp x )=-+-+-+-+ The while loop should add each of the series terms. The program error as defined below is smaller than 0.01. Error is the exact value (i.e. exp(2)), minus the approximate value (i.e., the current series sum) should exit the loop when the absolute absolute error-lexact-approx Use fprintf within the loop such...
2. What is the value of x alter the following code is executed # include<iostream> using namespace std; int main int t-0, c- 0,x-3; while (c < 4) t=t+x; cout << x return 0; a) 3 b) 21 c) 24 d) 48 3. What is the output of the following code? # include<iostream> using namespace std; int main0 int a- 3; for (int i 5; i >0; i) a a+i cout << a << “ “ return 0; d) 8...
Question 1 QUESTION 2 Use the attached Matlab code as a basis to solve the following ordinary differential equation using Euler's method, with timestep of 0.1, from t-0to t-100. d)0) -0 - sin (5vt cos(у Plot y versus t from t=0 to t=100. How many local maxima are on this interval(do not include end points). Be careful to count them all! Answer should be an integer 1 w% Matlab code for the solution of Module 2 3 dt-9.1; %dt is...
Consider the following code: int w- 10; while (w>0) scanf("%d", &y); if(y>0){ V++i else The value stored in variable v at the end of the execution of the loop could best be described as the sum of all positive numbers scanned from the terminal the number of times the loop executed the sum of all non-positive numbers scanned from the terminal the number of positive integers scanned from the terminal the number of negative integers scanned from the terminal
You have the matrix below: a) 9 10 11 12 What will be displayed by the code: A(2:3,2:3) What will be displayed when you run the code below? b) a-0 while a<10 aa+3: end disp (a) d) Give the steps to find the roots of the following linear equation using MATLAB. rs + 2x4-5x3 + 7x2 + 12x + 20 = 0 a) Give MATLAB commands to plot, on the same figure, the two functions: f(t) = 3t2 +2t-0.5 g(c)-2t...
1. Give the Python program that computes the square of a number. The number is passed to the function as a parameter. The output is the square of this number. For example, the function can be used as shown below . . . . n = s q u a r e ( 7 ) . . . 2. Another very useful feature of Python is looping, which is more flexible than that available in BB. For example: while i...