Question

Compute the following problems using Math Lab.  Instructions: Answer All Questions using MATLAB commands. Question 1. Create a vector of the even whole numbers between 31 anb.... compute the length of the third side of a triangle given the lengths of the other two sides, given the cosine rule c- a

0 0
Add a comment Improve this question Transcribed image text
Answer #1

>> % question 1
>> even_whole = 31+1:2:75

even_whole =

Columns 1 through 11

32 34 36 38 40 42 44 46 48 50 52

Columns 12 through 22

54 56 58 60 62 64 66 68 70 72 74

>> % question 2
>> x = [2 5 1 6];
>> % a
>> x+16

ans =

18 21 17 22

>> % b
x = [2 5 1 6];
x(1)=x(1)+3;
x(3)=x(3)+3;
x

x =

5 5 4 6

>> % c
x = [2 5 1 6];
sqrt(x)

ans =

1.4142 2.2361 1.0000 2.4495

>> % d
>> x.^2

ans =

4 25 1 36

% question 3
>> x = [3 2 6 8]' , y = [4 1 3 5]'

x =

3
2
6
8


y =

4
1
3
5

>> sum(x)+ sum(y)

ans =

32

>> % b
>> x.^y

ans =

81
2
216
32768

>> % c
>> y./x

ans =

1.3333
0.5000
0.5000
0.6250

>> % d
>> x.*y

ans =

12
2
18
40

>> z=x.*y;
>> % e
>> x=sum(z)

x =

72

>> w=sum(z);
>> x = [3 2 6 8]'

x =

3
2
6
8

>> % f
>> x'*y-sum(z)

ans =

0

>> % question 4
>> % a
>> 2/2*3

ans =

3

>> 6-2/5+7^2-1

ans =

53.6000

>> 10/2\5-3+2*4

ans =

6

>> 3^2/4

ans =

2.2500

>> 3^2^2

ans =

81

>> 2+round(6/9+3*2)/2-3

ans =

2.5000

>> 2+floor(6/9+3*2)/2-3

ans =

2

>> 2+ceil(6/9+3*2)/2-3

ans =

2.5000

>> % question 5
>> x = 2:2:20 % insteal of 20 one could put bigger number

x =

2 4 6 8 10 12 14 16 18 20

>> % b
>> clear x
>> x = 10:-2:-4

x =

10 8 6 4 2 0 -2 -4

>> %c
>> clear x
>> x = 1:20;
>> x = 1./x

x =

Columns 1 through 6

1.0000 0.5000 0.3333 0.2500 0.2000 0.1667

Columns 7 through 12

0.1429 0.1250 0.1111 0.1000 0.0909 0.0833

Columns 13 through 18

0.0769 0.0714 0.0667 0.0625 0.0588 0.0556

Columns 19 through 20

0.0526 0.0500

>> % d
>> clear x
>> x = 0:20;
>> y = x+1;
>> x = x./y

x =

Columns 1 through 6

0 0.5000 0.6667 0.7500 0.8000 0.8333

Columns 7 through 12

0.8571 0.8750 0.8889 0.9000 0.9091 0.9167

Columns 13 through 18

0.9231 0.9286 0.9333 0.9375 0.9412 0.9444

Columns 19 through 21

0.9474 0.9500 0.9524

>> % question 6
>> xn = @(n) (-1)^(n+1)/(2*n-1);
>> xn

xn =

function_handle with value:

@(n)(-1)^(n+1)/(2*n-1)

>> % question 7
>> % function handle for hypoteneous
>> f = @(a,b) sqrt(a.^2,b.^2);
>> f

f =

function_handle with value:

@(a,b)sqrt(a.^2,b.^2)

>> for i=1:100 x(i)=xn(i); end
sum(x)

ans =

0.7829

>> % question 7
>> % function handle for hypoteneous
>> f = @(a,b) sqrt(a.^2+b.^2);
>> f

f =

function_handle with value:

@(a,b)sqrt(a.^2+b.^2)

>> % function handle for cosine rule
>> g = @(a,b,t) a.^2 + b.^2 -2.*b.*a.*cos(t);
>> g

g =

function_handle with value:

@(a,b,t)a.^2+b.^2-2.*b.*a.*cos(t)

% question 9
x=linspace(0,4);
>> subplot(2,2,1); plot(x,x,'r--'); title('x');...
subplot(2,2,2); plot(x,x.^3,'k--'); title('x^3');...
subplot(2,2,3); plot(x,exp(x),'c-.'); title('exp(x)');...
subplot(2,2,4); plot(x,exp(x.^2),'g--'); title('exp(x^2)');

80 60 40 20 exp(x) 0 exp(x2) 60 10 106 40 20 0

>> % question 10
>> x = linspace(0.01,0.1,1000); % linspace divide interval into 1000 equal segments
>> plot(x,sin(1./x))

0.8 0.6 0.4 0.2 0 -0.2 0.4 -0.6 -0.8 -1 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11

Add a comment
Know the answer?
Add Answer to:
Compute the following problems using Math Lab.   Instructions: Answer All Questions using MATLAB commands. Question 1....
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
  • Solve in MATLAB Problem 3: Given the vector x- [2 1 0 6 2 3 5...

    Solve in MATLAB Problem 3: Given the vector x- [2 1 0 6 2 3 5 3 4 1 3 2 10 12 4 2 7 9 2 4 51 use a for loop to (a) Add up the values of all elements in x (b) Compute the cumulative sum, y, of elements in x You can check your results using the built-in functions sum and cumsum. Q.5 What is the value of the sum of elements in vector x?...

  • Using Matlab; Please show written program to execute and instructions to create plot: 1. Create a...

    Using Matlab; Please show written program to execute and instructions to create plot: 1. Create a vector of x values from 0 to 20 pi, with an increment of pi/100. y=x sin (x) and z= x cos (x) a) create a figure window with two subplots. In first subplot create an x versus y plot and in the second subplot create an y versus z plot. b) create a polar plot of x and y. Add title and labels to...

  • 1. In MATLAB on your computer (preferably) or on a workstation, Let x = [3456] a)...

    1. In MATLAB on your computer (preferably) or on a workstation, Let x = [3456] a) Add 10 to each element ofx. Note that you can add a number to a matrix or vector b) Add 3 to odd-index elements ofx (keep using the original x [3 4 5 6] for each step) c) Compute the square of each element of x

  • I am using a 2016 version of Matlab. I cannot figure out part a of this...

    I am using a 2016 version of Matlab. I cannot figure out part a of this problem. 8. Define the variables x = 0.85, y = 12.5, and then use them to create a row vector that has the following elements: y.y*,In(e)x y.and x + y a) By using the vector indexing take the 2nd element of the vector and add it to 3rd ,ln(-),x * y,and x + y element assign it to variable Exampl1

  • solve it by using matlab Question 2) (2.5 points) Examine the following trigonometric identity: sin'(x) =...

    solve it by using matlab Question 2) (2.5 points) Examine the following trigonometric identity: sin'(x) = (3 sin(a) – sin(3.c)) Verify that this identity is valid. To do so, define a variable x as x = 84 (in degrees!). Compute the left and right sides of the identity and assign them to variables p2left and p2right. Because x is in degrees, make sure you are using the correct trig function! Use the help function if you are unsure. Question 1)...

  • Please provide MATLAB code and plot, about system response. Will thumbs up. Thanks. Question 1: MATLAB contains a built-...

    Please provide MATLAB code and plot, about system response. Will thumbs up. Thanks. Question 1: MATLAB contains a built-in function called conv which performs the convolution of two vectors: >> help conv conv Convolution and polynomial multiplication. C - conv(A, B) convolves vectors A and B. The resulting vector is length MAX ([LENGTH (A)+LENGTH (B)-1, LENGTH(A),LENGTH (B) 1) If A and B are vectors of polynomial coefficients, convolving them is equivalent to multiplying the two polynomials. Compute the system response...

  • To Be Done Only in MatLab Please use the format provided: The derivative can be computed numerically using the definiti...

    To Be Done Only in MatLab Please use the format provided: The derivative can be computed numerically using the definition of the differentiation. with a small For example, derivative of f(x) = x, for () 1 with h = 0.01 is given by x x= 0:0.01 :1; Note that, diff(x), for a vector X, is [X(2)-X(1) X(3-X(2) Xn)-Xn1) So diff gives you one fewer points 2 for-2 IS 2 with h-0.01 . Then plot f(x) and g(x)-rx) Use the above...

  • using matlab Create the following matrix B. [18 17 16 15 14 13] 12 11 10...

    using matlab Create the following matrix B. [18 17 16 15 14 13] 12 11 10 9 8 7 6 5 4 3 2 1 Use the matrix B to: (a) Create a six-element column vector named va that contains the elements of the second and fifth columns of B. (6) Create a seven-element column vector named vb that contains elements 3 through 6 of the third row of B and the elements of the second column of B. Create...

  • Need help with this Matlab program %% Exercise 1 % NOTE: Please suppress output--i.e., use a...

    Need help with this Matlab program %% Exercise 1 % NOTE: Please suppress output--i.e., use a semicolon ';' at the end of any % commands for which the output is not necessary to answer the question. % Delete these notes before turning in. % Define input variable theta as discretized row vector (i.e., array). theta = ??; % Define radius. r = ??; % Define x and y in terms of theta and r. x = ??; y = ??;...

  • Assume that y is a column vector with ten elements, write matlab code that will create...

    Assume that y is a column vector with ten elements, write matlab code that will create a stem plot of the vector starting at a horizontal axis value of 1. Add code that will create the stem plot of the vector starting at a horizontal axis value of 0. Create additional code that creates a stem plot but plots y at every other horizontal value (i.e., 0, 2, 4, etc)

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