Question

Matlab coding assistance. Having some difficulty please help! thank you so much in advance! %% Task...

Matlab coding assistance. Having some difficulty please help! thank you so much in advance!

%% Task 9

% use logical tests to locate and update subsets of a matrix

% Step 1: Create vec, a row vector of 5 random integers on the closed interval [-10,10].

% Step 2: Use a logical mask to count the number of positive values (code provided is already sufficient)

mask = vec > 0

count = sum(mask)

% Step 3: Use the find function to locate where the positive values are in

% the vector (code provided is already sufficient)

inds = find(vec > 0)

% Step 4: Display only the positive values in vec (index into vec using the inds variable)

% Step 5: Negate the positive values by indexing into

% vec using the mask variable, and multiplying all those values by -1

.

%% Task 10

% Matrix multiplication

% Step 1:

%a) Define matrices A, B, and C as shown in Ex 42

% b) compute the expressions 3*A and A+3

% c) compute the expressions A*C, C*A, C*C and C.*C

% comment out any expression that does not compute successfully

% c) compute the expressions A*A and A.*A

% (Be sure you understand the difference between these two operations.

% Step 2:

% a) define matrices A, B and C as shown in Ex 43

% b) compute the matrix operations A*A,B*B and C*C

% comment out any expression that does not compute successfully

% c) use the size function to display the dimensions of B and C

% then compute the matrix operations B*C and C*B

% comment out any expression that does not compute successfully

% (Be sure you understand how to predict which the matrix products will

% compute, along with the dimensions of the result.)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
>>r = randi([10 50],-10,10); //a row vector of 5 random integers on the closed interval [-10,10]

>>vec=r;

Display only the positive values in vec (index into vec using the inds variable)

len=length(vec);
for inds=1:len;

if vec(inds)>=0

P(inds)=vec(inds);

end

disp(P)

Add a comment
Know the answer?
Add Answer to:
Matlab coding assistance. Having some difficulty please help! thank you so much in advance! %% Task...
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
  • I NEED HELP WITH THIS 2 PROBLEMS PLEASE! THANK YOU SO MUCH Given below is a...

    I NEED HELP WITH THIS 2 PROBLEMS PLEASE! THANK YOU SO MUCH Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count = @; for (int i = 0; i < SIZE; i++) { if (arr1[1] > arr2[i]) count++; return count; } Task 1: (10...

  • i've been having a hard time, i appreciate your help, thank you so much in advance!...

    i've been having a hard time, i appreciate your help, thank you so much in advance! can you please circle the answers thank you 1 2 3 (1 point) It is necessary for an automobile producer to estimate the number of miles per gallon achieved by its cars. Suppose that the sample mean for a random sample of 150 cars is 29.1 miles and assume the standard deviation is 2.4 miles. Now suppose the car producer wants to test the...

  • Please help answer this question? Please note that no dimensions were provided. Thank you so much

    Please help answer this question? Please note that no dimensions were provided. Thank you so much 04-BS-15 Engineering Graphics & Design Process December 2018 QUESTION 1 (50 MARKS) For the part shown below, Sketch an appropriate set of orthographic views, using third-angle projection. (10 marks) Fully dimension the sketch in part a) using professional standards. Use "xx" in place of numerical values in the dimensions. (10 marks) Describe and sketch an appropriate sequence of feature-based solid modelling operations that could...

  • Please help me answer this question? Please note that no dimensions were given. Thank you so much

    Please help me answer this question? Please note that no dimensions were given. Thank you so much 04-BS-15 Engineering Graphics & Design Process May 2012 QUESTION 1 For the part shown below, Sketch an appropriate set of orthographic views, using third-angle projection. (10 marks) values in the dimensions. (10 marks) could be used to create this geometry using parametric, feature-based solid modelling CAD a) b) Fully dimension the sketch in part a) using professional standards. Use "xx' in place of...

  • In this exercise you will work with LU factorization of an matrix A. Theory: Any matrix A can be ...

    In this exercise you will work with LU factorization of an matrix A. Theory: Any matrix A can be reduced to an echelon form by using only row replacement and row interchanging operations. Row interchanging is almost always necessary for a computer realization because it reduces the round off errors in calculations - this strategy in computer calculation is called partial pivoting, which refers to selecting for a pivot the largest by absolute value entry in a column. The MATLAB...

  • Hey guys, I need some help solving this problem. thank you very much in advance! Pontfolio Optimization Task 4 Suppose the shares of two different companies give you the same return on average...

    Hey guys, I need some help solving this problem. thank you very much in advance! Pontfolio Optimization Task 4 Suppose the shares of two different companies give you the same return on average. Does it make sense to distribute your money and buy some shares of each company? Or would it be better to invest all the money into only a single company? Common sense says: "distribute" Why? Let's see... What at all could we gain if the return is...

  • Need help with this question on matlab. Show code please! Salmon_dat.csv 272395 286156 391573 461443 401998...

    Need help with this question on matlab. Show code please! Salmon_dat.csv 272395 286156 391573 461443 401998 313120 240763 297488 446152 480276 420555 277697 357375 331788 420879 332479 320947 359853 300917 403286 416419 345028 256049 281980 286625 278560 344422 317956 219688 259337 208197 189419 272884 360673 248860 306981 401711 867728 870035 921314 846026 570413 493708 275954 518942 480284 809799 677171 589937 1129664 1152642 Exercise 1: Salmon Runs Download the file salmon-dat.csv included with the homework. This file con- tains the annual...

  • For this project, each part will be in its oun matlab script. You will be uploading a total 3 m f...

    For this project, each part will be in its oun matlab script. You will be uploading a total 3 m files. Be sure to make your variable names descriptive, and add comments regularly to describe what your code is doing and hou your code aligns with the assignment 1 Iterative Methods: Conjugate Gradient In most software applications, row reduction is rarely used to solve a linear system Ar-b instead, an iterative algorithm like the one presented below is used. 1.1...

  • PLEASE help me with the answers for b, c, and d! Especially d (you do not have to create a histogram for me)! Thank you so much!!! 4) You've been elected to the board, and to gather some inf...

    PLEASE help me with the answers for b, c, and d! Especially d (you do not have to create a histogram for me)! Thank you so much!!! 4) You've been elected to the board, and to gather some information, you send out a survey to all residents about how often they think the board should meet each quarter. You get the following 60 responses: 4 2 3 2 443 3 344 4 4 2 3 2 2 4 44 34...

  • Consider a cylindrical capacitor like that shown in Fig. 24.6. Let d = rb − ra...

    Consider a cylindrical capacitor like that shown in Fig. 24.6. Let d = rb − ra be the spacing between the inner and outer conductors. (a) Let the radii of the two conductors be only slightly different, so that d << ra. Show that the result derived in Example 24.4 (Section 24.1) for the capacitance of a cylindrical capacitor then reduces to Eq. (24.2), the equation for the capacitance of a parallel-plate capacitor, with A being the surface area of...

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