Question

USING MATLAB

Code for pseudo Random
Input N

M=0

For i=1 to N

X=rand#

Y=rand#

If X^2+ y^2 <= 1, then M=M+1

End the loop

Print M/N (This is the probability)

Print M/N (this is approximately = Py

Answer #1

clc;

clear all;

close all;

N = input('input a natural number');

X =randn(1,N);

Y =randn(1,N);

M=0;

for i =1 : N

if((X(i))^2 + (X(i))^ 2)<= 1

M=M+1;

end

end

display('The probability is ');

M/N

This program is written as per the psuedo code.

sample output is attached.

The rand() function in Matlab produces a pseudo-random number
that is uniformly distributed in (0, 1). How would you transform
the output from this function if you wanted numbers uniformly
distributed between 7 and 13?

USING MATLAB
(A) Use the rand command to generate “X” of size [10000 1] and
the command histogram to plot the probability distribution of “X”
along with axis labels and a title that includes the mean and
variance for “X”. (B) Use a while loop and the rand command to
generate “X1”, also of size [10000 1] but with each element of “X1”
being the mean of 2 “samples” generated using rand, i.e. a “sample
size” of 2 separate numbers...

Code in Matlab.
I need to make a diamond shape with *
I get part of it with the code below.
Instructions are: " Given the value of N print diamond of N +
(N-1) rows. For example, if N = 5 it should print a diamond."
clc
clear
n = input ('number of rows \n')
o = input ('number of inverted rows \n')
t = (o-1)
for i = 1:n
for k = 1:n-i
fprintf (' ');
end
for...

how do you generate data for a y random variable in matlab?
If x has uniform distribution (0,1)
y has uniform distribution (a,b)
Then write a matlab code using rand() command to generate data
from distribution of y
y = ? + ?x
a,b, rand()

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

Can you rewrite this MATLAB code using a while loop instead of a
for loop?
%formatting
clc, clear, format compact;
%define variables
k=1;
b=-2;
x=-1;
y=-2;
%while loop initialization
for k <= 3
disp([num2str(k), ' ',num2str(b),' ',num2str(x),'
',num2str(y),]);
y = x^2 -3;
if y< b
b = y;
end
x = x+1;
k = k+1;
end

d = int(input('Enter the date: '))
m = int(input('Enter the month: '))
y = int(input('Enter the year: '))
if m<3:
m = m + 12
y = y - 1
a = (2*m) + (6*(m+1)/10)
b = y + (y/4) + (y/400) - (y/100)
c = d + a + b + 1
f = c / 7
if f == 0:
print ('Sunday')
elif f == 1:
print ('Monday')
elif f == 2:
print ('Tuesday')
elif f ==3:
print...

MATLAB CODE REQUIRED
Consider the problem of estimating y(0.5) for the boundary-value
problem
y''+ y' = y + 2, y(0) = 0, y'(1) = 2. Find the solution using 2
approaches:
(b) Use finite difference with n =
10.Please provide Matlab code. What is y(0.5) value with
Matlab?
(c) Using bvp4c. Please provide Matlab
code. What is y(0.5) value with Matlab?

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

Using Matlab to solve the problem below
Given
X=[-2 -1 0 1 2]
Y=[1.5 3.2 4.5 3.4 2]
a). Plot a scatter plot of the data
b). Determine the coefficients of the
polynomial ?0 + ?1? +
?2?2 which best fits the data
c). Plot this function on the same plot as in
part ‘a’.
USE MATLAB CODE ONLY!
USE MATLAB CODE ONLY!
THANK YOU

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 7 minutes ago

asked 9 minutes ago

asked 32 minutes ago

asked 52 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 2 hours ago

asked 2 hours ago

asked 2 hours ago

asked 2 hours ago

asked 2 hours ago

asked 2 hours ago