Upload
ellis
View
31
Download
0
Embed Size (px)
DESCRIPTION
Lecture 5 FOR Looping. Summation Symbolic differentiation Counting ATCG. Summation. x = 1.5. x = 1.5. floor(x). ceil(x). 2. 1. Flow chart. S=0. for n=1:N. sn=floor(n^2)+ceil(2*n/3) S=S+sn. Symbolic Differentiation. >> x=sym('x'); >> diff(tanh(x)) ans = 1-tanh(x)^2. - PowerPoint PPT Presentation
Citation preview
軟體實作與計算實驗 1
SummationSymbolic differentiationCounting ATCG
Lecture 5 FOR Looping
軟體實作與計算實驗 2
Summation
x = 1.5
floor(x)
1
x = 1.5
ceil(x)
2
軟體實作與計算實驗 3
Flow chart
sn=floor(n^2)+ceil(2*n/3) S=S+sn
S=0
for n=1:N
軟體實作與計算實驗 4
Symbolic Differentiation
>> x=sym('x');>> diff(tanh(x)) ans = 1-tanh(x)^2
軟體實作與計算實驗 5
Symbolic differentiation
>> x=sym('x');>> diff(x.^3+2*x) ans = 3*x^2+2
軟體實作與計算實驗 6
Symbolic Differentiation
demo_diff.m
• Input a string, fstr• Plot the function specified by fstr• Plot the derivative of the given function
軟體實作與計算實驗 7
Example
-5 -4 -3 -2 -1 0 1 2 3 4 5-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
function of x:tanh(x)
fx1 =
Inline function: fx1(x) = 1-tanh(x).^2
軟體實作與計算實驗 8
Histogram
Sample space of a die: {1,2,3,4,5,6}Count occurrences of outcomes
軟體實作與計算實驗 9
Create a sample
n=1000;s=ceil(rand(1,1000)*6);h=hist(s,[1 2 3 4 5 6]);
軟體實作與計算實驗 10
hist(s,[1 2 3 4 5 6])
軟體實作與計算實驗 11
c=s(i); count(c) = count(c) +1;
軟體實作與計算實驗 12
Flow chart :
c = s (i); count(c) = count(c)+1;
n=length(s);count=zeros(1,6);
for i=1:n
軟體實作與計算實驗 13
n=length(s);count=zeros(1,6);for i=1:n c = s (i); count(c) = count(c)+1;end
軟體實作與計算實驗 14
Flow chart :
ind = find(s==i); count(i) = length(ind);
n=length(s);count=zeros(1,6);
for i=1:6
軟體實作與計算實驗 15
n=length(s);count=zeros(1,6);for i=1:6 ind = find(s==i); count(i) = length(ind);end
軟體實作與計算實驗 16
DNA sequence
ATCG sequence
load mitochondriamitochondria(1:200)
軟體實作與計算實驗 17
mitochondria(1:200)
gatcacaggtctatcaccctattaaccactcacgggagctctccatgcatttggtattttcgtctggggggtgtgcacgcgatagcattgcgagacgctggagccggagcaccctatgtcgcagtatctgtctttgattcctgcctcattctattatttatcgcacctacgttcaatattacaggcgaacatacctacta
軟體實作與計算實驗 18
ATCG
Calculate probabilities of a,t,c,g occurring in a given ATCG sequence.
?)''Pr(
?)''Pr(
?)''Pr(
?)''Pr(
gx
cx
tx
ax
軟體實作與計算實驗 19
Switch
cc=mitochondria(i); switch cc case 'a' count(1)=count(1)+1; case 't' count(2)=count(2)+1; case 'c' count(3)=count(3)+1; case 'g' count(4)=count(4)+1; end
軟體實作與計算實驗 20
Flow chart
cc=mitochondria(i); switch cc
. . . end
load mitochondrian=length(mitochondria);count=zeros(4);
for i =1:n
軟體實作與計算實驗 21
load mitochondrian=length(mitochondria);count=zeros(1,4);for i =1:n cc=mitochondria(i); switch cc case 'a' count(1)=count(1)+1; case 't' count(2)=count(2)+1; case 'c' count(3)=count(3)+1; case 'g' count(4)=count(4)+1; endend