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);
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...
% 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);
Problem 1....... you can use Matlab The following Scilab code generates a 10-second “chirp” with discrete...
Problem 1....... you can use Matlab The following Scilab code generates a 10-second “chirp” with discrete frequencies ranging from 0 to 0.2 with a sampling frequency of 8 kHz. clear; Fs = 8000; Nbits = 16; tMax = 10; N = Fs*tMax+1; f = linspace(0.0,0.2,N); x = zeros(f); phi = 0; for n=0:N-1 x(n+1) = 0.8*sin(phi); phi = phi+2*%pi*f(n+1); end sound(x,Fs,Nbits); sleep(10000); //allows full sound to play Add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the...
Recall that the command diff(f(x),x) symbolically finds the derivative of the function f. Recall also that...
Recall that the command diff(f(x),x) symbolically finds the derivative of the function f. Recall also that the derivative is itself a function which can also be differentiated, giving us the second derivative of f, and so on. MATLAB will easily compute higher order derivatives using the command diff(f(x),x,n) Where n represents which derivative you want. Later, it will be very useful to find patterns in higher order derivatives. Ordinarily, this is most easily done by NOT simplifying the resulting expression,...
JUST NEED PART G PLEASE. THANK YOU. Consider the vector a= <5,3>. Find another vector b...
JUST NEED PART G PLEASE. THANK YOU. Consider the vector a= <5,3>. Find another vector b in R2such that ab<0. Find the following for your specific vectors. |a| |b| ab compab projab On a coordinate axis, graph a, b, and projab. Explain why ab<0in terms of geometry and referring to your answer for part f. This answer should be in complete sentences and thoroughly explain what is happening geometrically. You should include words like magnitude and component.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT