A=[-6,8,2;1,-3,20;15,-10,5];
Write a program that computes the array B by computing the natural logarithm of all the elements of A whose value is greater than or equal to 1. Otherwise add 30 to each element that is less than 1. Do this in two way.
A) By using a for loop with conditional statements
B)By using a logical array as a mask
MATLAB CODE
Matlab:
A = [-6 8 2;1 -3 20;15 -10 5];
A(A<1) = A(A<1)+30;
B = log(A);
disp('using conditional mask');
disp(B);
A = [-6 8 2;1 -3 20;15 -10 5];
for i=1:3
for j=1:3
if A(i,j)<1
A(i,j) = A(i,j)+30;
end
end
end
B = log(A);
disp('using for loop');
disp(B);
command window log:
using conditional mask
3.1781 2.0794 0.6931
0 3.2958 2.9957
2.7081 2.9957 1.6094
using for loop
3.1781 2.0794 0.6931
0 3.2958 2.9957
2.7081 2.9957 1.6094
>>
A=[-6,8,2;1,-3,20;15,-10,5]; Write a program that computes the array B by computing the natural logarithm of all...
In Matlab
Consider the array A. 10 3 5 -4 12 -5 9 2 A= 6 13 -8 11 115 -5 4 1 Write a program that computes the array B by computing the square of all the elements of A whose value is greater than 10 and multiplying 5 to each element that is less than or equal to 10. You need to use a logical array as a mask.
7eatng that function Write a C++ program that does the following: Fill an array of 123 elements using srand) and rand) with random numbers between 150 and 667. Fill an array of 123 elements with random numbers between 150 and 667. Using a loop. Fill an array of 123 elements with random numbers between 150 and 667. Using a for loop Use a void function to fill an array of 123 elements with random numbers between 150 and 667, Possible...
[MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a vector. The cumulative product, pj, of the jth element of the vector x, xj, is defined by pj = (x1)(x2) … (xj) for j = 1:length of the vector x. DO NOT USE CUMPROD For example, when you run your function it should look like this: >> x = [2 3 4 2]; >> myMultProd(x) >> ans = 2 6 24 48 That is,...
matlab only
ale boh th Blac Your job is to draw exercise making sure that the flowchart is correspondent to the MATLAB code given. That means that variable names, and order of calculations need to match between the code and the nlowchart. Finally, make sure you understand the MATLAB code. It is assumed that if you can do the flowchart of a complicated code, you can perform logical statements of that magnitude. Make your flow chart more detailed than ones...
1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers of 1 through 15. Display your result back to the user with 2 decimal places (yes, 2 decimal places). You must implement your code using a for loop. The result should have the following format: The multiplication of 10*1 =10.00 The multiplication of 10*2 =20.00 The multiplication of 10'3=30.00 The multiplication of 10*15=150.00 2. (35 Points) Write MATLAB code to prompt a user for...
JAVA - Natural Quick Sort .txt and Return ----------------------------------------------------------------------------- The program should input a .txt file like below and must use a Quick sort Algorithm ================ 6 10 4 19 10 12 8 6 0 1 2 3 ================ The first number "6" represents the index of the element to return after sort the second number on the top "10" represents the number of elements or size of array. The following numbers and lines are the elements that need to...
Answer with simple java code and comments
This homework deals with the problem of partitioning an array. We'll define partitioning to mean arranging the elements of an array around a certain "pivot, " element such that all elements to the left of the pivot are strictly less than the pivot, and all elements to the right of the pivot are greater than or equal to the pivot. To simplify things a little bit, we'll assume that the pivot element is...
2. (aj An object thrown vertically with a speed vo reaches a height h at time t,where with a user defined function that computes the time required to reach a Write a MATLAB program specified height h, for a given value of vo. The function's imput should be h, we and g Testverurtrott" for the case where h-100 m, vee50 m/s and g-9,82 /by free hand. Write the MATLAB you will run/call the function with these given values (b) Write...
Q1. Write a program in Java a. Create 2 separate arrays, of user defined values, of same size b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....
C++ Program Your program should: 1) Validate that the number of commandline arguments, after a.out is in the range [1,6]. If not, print an error message and stop the program with exit code 1. 2) Declare a vector of ints or array of ints to store the arguments. Use a loop to parse all the arguments (except a.out) into your vector/array. 3) Use a loop to calculate the greatest number (maximum). If the maximum is greater than 100, print "XNN"...