0% found this document useful (0 votes)
36 views7 pages

Create a function in MATLAB for calculating the mean (תלחות) and standard deviation (ןקת תייטס)

The document provides MATLAB code for several functions: 1) A function to calculate the mean and standard deviation of a data set. 2) A function to calculate the sum of the first N terms of a geometric series. 3) A function to calculate the sum of an arbitrary geometric series, checking for divergence. 4) A function to find the largest value in a matrix. 5) A function to find all prime numbers of the form 2n - 1 for n from 1 to 20. 6) Code to plot the bifurcation diagram of the roots of the equation x^3 + cx = 0.1 for -3 <= c <= 2.

Uploaded by

Jason Wong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views7 pages

Create a function in MATLAB for calculating the mean (תלחות) and standard deviation (ןקת תייטס)

The document provides MATLAB code for several functions: 1) A function to calculate the mean and standard deviation of a data set. 2) A function to calculate the sum of the first N terms of a geometric series. 3) A function to calculate the sum of an arbitrary geometric series, checking for divergence. 4) A function to find the largest value in a matrix. 5) A function to find all prime numbers of the form 2n - 1 for n from 1 to 20. 6) Code to plot the bifurcation diagram of the roots of the equation x^3 + cx = 0.1 for -3 <= c <= 2.

Uploaded by

Jason Wong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Create a function in MATLAB for calculating the mean

( )and standard deviation ()


Tip. Use functions: sum, length

Create a function in MATLAB for calculating the mean


( )and standard deviation ()
Tip. Use functions: sum, length
function [mean,stdev] = stat(x)
n = length(x);
mean = sum(x)/n; OR mean = avg(x,n);
stdev = sqrt(sum((x-mean)2 /n));
end
Create a function in MATLAB for calculating the sum of
the N+1 first terms of geometric series
1 + a + a2 + ... + aN (4 lines only!!!).

Create a function in MATLAB for calculating the sum of


the N+1 first terms of geometric series
1 + a + a2 + ... + aN .

function ssum = geom(a,N)


n=0:N;
ssum = sum(a.n );
end
Create a function in MATLAB to calculate the sum of an
arbitrary geometric series.

Create a function in MATLAB to calculate the sum of


an arbitrary geometric series.
function ssum = geomInf(a,N)
if(N==inf)
if(abs(a)>=1) error(This geometric series will diverge.);
else ssum=1/(1-a);
end
else n=0:N;
ssum = sum(a.n );
end
end
Create a function in MATLAB to calculate the biggest
value of a matrix.

Create a function in MATLAB to calculate the biggest


value of a matrix.
function y = big(x)
y=abs(x(1,1));
for i=1:size(x,1)
for j=1:size(x,2)
if abs(x(i,j))>y
y=abs(x(i,j));
end
end
end
Create a function in MATLAB to find all prime numbers
of the form 2n 1 for n = 1..20.
Tip. Use functions: factor

Create a function in MATLAB to find all prime numbers


of the form 2n 1 for n = 1..20
n=20;
k=0;
for i=1:n
if (factor(2i -1)==2i -1)
2i -1
k=k+1;
end;
end
k

:MATLAB
x 3 + cx = 0.1,

3 c 2.

roots ,imag :


x 3 + cx = 0.1, 3 c 2. :MATLAB

a=[];
for c=-3:0.01:2
q=roots([1,0,c,-0.1]);
for j=1:size(q,1)
if imag(q(i))==0 a=[a;[c,q(i)]];
end
end
end
plot(a(:,1),a(:,2),.)

You might also like