Q. What does following Code Compute ?
Ans. Here we have A is a m×n matrix ,and x(1),x(2), .....,x(n) are n values or weights or scalars , here this code generate a column matrix b of order m×1 which is sum of the product of the j'th column of matrix A and j'th weight that is x(j) where summation varies from j = 1 to j = n .
Q. What Operation third Line is performing.
Ans. Third line is updating matrix b , in each step for a particular value of j it is adding product of j'th column of matrix A and j'th weight that is A(:,j)*x(j) to the matrix b .
2. What does the following code compute? Explain what operation the third line is per- forming....
Using MATLAB please. A = rand(m,n) x = rand(n,1) b = A * x 1. What does the following code compute? Explain what operation the third line is per- forming b = zeros(m, 1); for i = 1:m b(i) = A(i,:) * x; end Make a copy of the relevant MATLAB function you wrote earlier, and use this code in place of the two loops you wrote. Time both codes on a sufficiently large problem. Which performs faster?
Verify that the operation count is 5n for n unknowns for this algorithm. Explain which lines correspond to what operation count. function x = tridisolve(a,b,c,d) x = d; n = length(x); % forward elimination for j = 1:n-1 mu = a(j)/b(j); b(j+1) = b(j+1) - mu*c(j); x(j+1) = x(j+1) - mu*x(j); end % back solve x(n) = x(n)/b(n); for j = n-1:-1:1 x(j) = (x(j)-c(j)*x(j+1))/b(j); end end
Explain each line of code. What does the routine do. model small .stack 100h .code main proc mov BL, 36 yor BL, 40h mov CL, 16h m: mov ah,6 mov dl, bl. add DL, CL int 21h dec CL jnz m mov ax,4C00h int 21h main endp end main Good luck!
Question 2 (a) Provide a single line of C++ code that will declare a variable that points to a string value, the variable is named x. [2 marks] (b) You have array c declared as string *c [5]; Give the single line of C+ + code that will assign the string pointer stored in variable x (from above) to the third element of the array c. [2 marks] (c) Write a for loop that initialises the contents of each element...
In the MATLAB code below what does the line: A(i) = 0; do? Is A(i) just a variable or does in index something? P=1000; r=0.01; n=1; f for loop to calculate monthly interest and yearly interest for i=1:10 A(i)=0; for j=1:12 Am=P* (1+r)^n; P=Am; end A(i) = Am; end % display the amount compounded annually for 10 years i=1:10; table=[i', A']; disp('year Amount') fprintf('%2d %6.2f \n', table')
Please provide code and final answer. The code provided solves the boundary value problem 2 dr2 cos(a), J(1) , y(5)2.on the interval Toxksusing a Centred approximation of the derivative term and N= 100 nodes 1 we% Matlab code for the solution of Module 2 3 xright=5; 4 N 100; 5 x-linspace(xleft,xright,N); x x'; %this just turns x into a column vector dx- 7 (xright-xleft)/(N-1); %If theres N nodes, theres N-1 separations . 9 yright 2; 10 here is the matrix...
Explain the following code, line by line. As well as the is going on over all. #include <stdio.h> int main() { int a[30]; int i,j,lasti; int num; lasti=0; // scanf the number scanf("%d",&a[0]); while (1) { // sacnf the new number printf("Enter another Number \n"); scanf("%d",&num); for(i=0;i<=lasti;i=i+1) { printf("%d \n",a[i]); // we check if the num that we eneterd is greter than i if(a[i] > num) { for(j=lasti; j>= i;j--) { a[j+1]=a[j]; } a[i]=num; lasti++; break; } }...
Using C++ please explain What is the Big-O time complexity of the following code: for (int i=0; i<N; i+=2) { ... constant time operations... Select one: o a. O(n^2) O b. O(log n) c. O(n) O d. 0(1) What is the Big-O time complexity of the following code: for(int i=1; i<N; i*=2) { ... constant time operations... Select one: O O a. O(n^2) b. 0(1) c. O(n) d. O(log n) O What is the Big-O time complexity of the following...
Explain what each line of the following snippet of code does: int *ptr; ptr = new int; *ptr = 10; cout << ptr << ' ' << &ptr << ' ' << *ptr; delete ptr; cout << ptr << ' ' << &ptr << ' ' << *ptr;
I want to know what is wrong with this code, and how to fix it please. i keep getting Error using contour (line 48) Z must be at least a 2x2 matrix. Error in Projectrevised (line 42) curve= contour(b,FOS1,h,'ShowText','on'); %% Constants w = 450000; l = 10; n = 6; SOM = 505000000; max = 10; min = 2; diff = (max-min)/n; FOS1 = zeros(n,n); FOS2 = zeros(n,n); i = 1; j = 1; Vm = (w*l)/2; %% FOS@different base&height...