Question

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);

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.

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 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 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 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 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...

% 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 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 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 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 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...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 6 minutes ago

asked 17 minutes ago

asked 23 minutes ago

asked 40 minutes ago

asked 43 minutes ago

asked 45 minutes ago

asked 46 minutes ago

asked 54 minutes ago

asked 54 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago