Question

Why it cannot display flop? you need to explain rather than just show me another code...

Why it cannot display flop?

you need to explain rather than just show me another code

MatLab

function b=Matrixvector(A,x)

n=length(x);
b=zeros(n,1);
flop=0;
for i=1:n
for j=1:n
b(i)=b(i)+A(i,j)*x(j);
flop=flop+2;
end
end
disp(b);
disp(flop);

Homework Answers

Answer #1

After copying the provided function over to a script file named 'Matrixvector.m'; when the below code is run, the output obtained is shown underneath.

Code:

clc
A = [1 2 1; 5 2 6; 8 9 5];
x = [1 2 3];
b = Matrixvector(A,x); % Calling the function

Output:

8
27
41
18

Explanation: In the output, the first three (for this example) elements are from disp(b) command in the Matrixvector function and the last element is the flop value. The last value will be the value of the flop; and the first three (for this example) only is the vector b.

Note: No change is required in the provided Matrixvector function.

Know the answer?
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
Similar Questions
This is LU deposition code of matlab. What's wrong with this code.... Thank you n and...
This is LU deposition code of matlab. What's wrong with this code.... Thank you n and B was given from above, what is for i = 1:n U(1,i) = A(1,i); L(i,1) = A(i,1)/U(1,1); %u(1,1)=1 end for j = 2:n for k = j:n U(j,k) = A(j,k)-L(j,1:j-1)*U(1:j-1,k); L(k,j) = (A(k,j)-L(k,1:j-1)*U(1:j-1,j))/U(j,j); end end for i = 1:n x(i) = B(i) / L(i,i:n)*U(i:n,i); end fprintf("Ans x = \n"); fprintf("%f \n", x);
This is my code and can you please tell me why it's not working? By the...
This is my code and can you please tell me why it's not working? By the way, it will work if I reduce 10,000,000 to 1,000,000. #include <iostream> using namespace std; void radixSort(int*a, int n) { int intBitSize = sizeof(int)<<3; int radix = 256; int mask = radix-1; int maskBitLength = 8;    int *result = new int[n](); int *buckets = new int[radix](); int *startIndex = new int[radix]();    int flag = 0; int key = 0; bool hasNeg =...
Problem 3 you can use Matlab and also i give u the Problem 1 code its...
Problem 3 you can use Matlab and also i give u the Problem 1 code its on Matlab Using the same initial code fragment as in Problem 1, add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the impulse response of an IIR bandpass filter with band edge frequencies 750 Hz and 850 Hz and based on a 4th order Butterworth prototype. Name your program p3.sce this is the Problem 1 code and the solutin clear; clc;...
I need to change the MATLAB code below to something else, but I need the solutions...
I need to change the MATLAB code below to something else, but I need the solutions to match each other. (Also try not to copy answer posted on chegg already) % % Problem 1.8 % clc; clear all; close all; % reset matlab w orthregdata; % load data n = length(a); w = ones(n,1); ma = w'*a/n; mb = w'*b/n; % ma = mean(a); % mb = mean(b); sa = norm(a-ma)/sqrt(n); sb = norm(b-mb)/sqrt(n); % sa = std(a,1); % Pass...
1: A) Given the following vectorized code: >>x=[1:10]; >>f=x.^2+2; Rewrite this code using a for loop...
1: A) Given the following vectorized code: >>x=[1:10]; >>f=x.^2+2; Rewrite this code using a for loop that defines each element of f one at a time. Make sure to preallocate memory to f before filling each spot. B) See the following code. Rewrite the code in one line using the find function and a For loop. then write it again using a while loop x=[-1 3 7 2 4 0]; v=[]; for i=1:length(x) if x(i)<=2 v=[v, x(i)]; end end please...
Problem 2 (explain each codes please) If more information if needed please let me know 1)...
Problem 2 (explain each codes please) If more information if needed please let me know 1) % time vector t=linspace(0,1,1000); x = zeros(size(t)); y = zeros(size(t)); Meaning: 3)% loop to find the value of x and y for different values of time for i=1:length(t) x(i) = v*cos(angle_theta)*t(i); y(i) = h+v*sin(angle_theta)*t(i)-(0.5*g*(t(i).^2)); end Meaning: 4)% find the first index where y<=0 i.e the ball hits the ground I = find(y<=0,1); fprintf('The ball hits the ground at distance of %f meters\n',x(I)); Meaning: 5)...
% This program calculates the Lagrange interpolating polynomial of a given % xp and returns the...
% This program calculates the Lagrange interpolating polynomial of a given % xp and returns the value clc, clear all; format short; x=[0 20 40 60 80 100];% This string can be filled by Matlab f_x=[26.0 48.6 61.6 71.2 74.8 75.2]; % You can create a separate function to fill f_x automatically n=length(x)-1; xp=input('Enter a value xp between 0 and 100: '); P_x=0; for i=1:n+1 L_k=1; for j=1:n+1 if j~=i L_k=L_k*(xp-x(j))/(x(i)-x(j)); end end P_x=P_x+f_x(i)*L_k; end disp ('The polynomial P_xp at...
Your objective in Problem 2 is to employ Euler's Method to determine what goes wrong when...
Your objective in Problem 2 is to employ Euler's Method to determine what goes wrong when the interval is [ 0, 1 ]. To this end, I want you to create another new script, EulerMethod3, which is intended to approximate the "solution" to the IVP given below.          dy/dx = (1/9)*(y^10)        where.          y(0) = 1.            over the interval. [ 0, 1 ] I was given the code below for a different question, but I don't know how to modify it to solve this...
MATLAB save output as array this is my code so far, I'm going to need to...
MATLAB save output as array this is my code so far, I'm going to need to save these as arrays or vectors i think to take some statistics on them. how do i save each walkers position relitive to time I should end up with 1000x 1000 matrix i think or 1000 arrays walkers=1000; %walkers=input('how many walkers do you want to simulate?') N = 1000; %N = input('how many steps do you want?') for k= 1:walkers displacement= randn(1,N); x =...
Modify this Matlab code for natural spline so it computes clamp Spline compclampspline(x,y,alpha,beta) alpha and beta...
Modify this Matlab code for natural spline so it computes clamp Spline compclampspline(x,y,alpha,beta) alpha and beta are the derivatives at the ends. Code for Natural Spline function [a,b,c,d]=compnatspline(x,y) function [a,b,c,d]=compnatspline(x,y) n=length(x); delx=(x(2:n)-x(1:n-1))'; dely=(y(2:n)-y(1:n-1))'; a=zeros(n,n); a(1,1)=1; a(n,n)=1; r(1)=0; r(n)=0; for row=2:n-1 r(row)=3*(dely(row)/delx(row)-dely(row-1)/delx(row-1)); a(row,row-1)=delx(row-1); a(row,row)=2*(delx(row-1)+delx(row)); a(row,row+1)=delx(row); end c=a\r'; clear a b(1:n-1)=dely./delx -delx/3.*(2*c(1:n-1)+c(2:n)); d(1:n-1)=(c(2:n)-c(1:n-1))./(3*delx(1:n-1)); a(1:n-1)=y(1:n-1); c=c(1:n-1);
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT