1 / 57

Lecture 5II

Lecture 5II. Markov Chain Roots of nonlinear functions Nested FOR loops. State. Initial population. denotes the initial population of being state. State transition. A person has a current state, e.g. S i Its next state may be any one of possible states State transition from S i to S j.

yale
Télécharger la présentation

Lecture 5II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 5II • Markov Chain • Roots of nonlinear functions • Nested FOR loops 軟體實作與計算實驗

  2. State 軟體實作與計算實驗

  3. Initial population denotes the initial population of being state 軟體實作與計算實驗

  4. State transition • A person has a current state, e.g. Si • Its next state may be any one of possible states • State transition from Si to Sj 軟體實作與計算實驗

  5. Transition probabilities denotes the probability of transition from to 軟體實作與計算實驗

  6. State 軟體實作與計算實驗

  7. State transition Populations after one time of state transition 軟體實作與計算實驗

  8. State transition Populations after one time of state transition Populations after k times of state transition k 軟體實作與計算實驗

  9. Exercise I • Draw a flow chart to calculate populations after k times of state transitions using for-loops • Write a matlab function to implement the flow chart • Find the result for v = 100 600 300 P = 0.1000 0.4500 0.4500 0.3333 0 0.6667 0.5000 0 0.5000 k=1 k=10 k=20 k=100 軟體實作與計算實驗

  10. Convergence Change Norm 軟體實作與計算實驗

  11. Convergence The answer converges if 軟體實作與計算實驗

  12. for i=1:k v_new=P'*v norm(v-v_new)<10^-6 Yes:converge break v=v_new 軟體實作與計算實驗

  13. for i=1:k v_new=P' *v; if norm(v_new-v)<10^-6 break else v=v_new end end 軟體實作與計算實驗

  14. Exercise II Draw a flow chart to illustrate finding by a for-loop Implement your flow chart by a matlab function 軟體實作與計算實驗

  15. change=1 for i=1:k change>10^-6 v_new=P'*v v_new=P'*v norm(v-v_new)<10^-6 change=norm(v-v_new) v=v_new Yes:converge break v=v_new 軟體實作與計算實驗

  16. while-loop change=1 change>10^-6 v_new=P'*v change=norm(v-v_new) v=v_new 軟體實作與計算實驗

  17. change = 1 while change < 10^-6 v_new=P' *v; change = norm(v-v_new); v=v_new end 軟體實作與計算實驗

  18. Exercise III Draw a flow chart to illustrate finding by a while-loop Implement your flow chart by a matlab function 軟體實作與計算實驗

  19. Nonlinear system 軟體實作與計算實驗

  20. A set of nonlinear functions 軟體實作與計算實驗

  21. Function evaluation function F = myfun(x) F(1) = x(1).^2 + x(2)^2-4; F(2) = x(1) - x(2); return 軟體實作與計算實驗

  22. x=linspace(-2,2); plot(x,x); hold on; plot(x,sqrt(4-x.^2)) plot(x,-sqrt(4-x.^2)) 軟體實作與計算實驗

  23. Least square of nonlinear functions 軟體實作與計算實驗

  24. Find a zero x0= ones(1,2)*2; x = lsqnonlin(@myfun,x0) y=myfun(x); sum(y.^2) CHECKING 軟體實作與計算實驗

  25. Multiple roots v=[] demo_lsq.m for i=1:n x0= ones(1,2)*2; x = lsqnonlin(@myfun,x0) v=[v;x]; plot(x(1),x(2),'o'); 軟體實作與計算實驗

  26. 軟體實作與計算實驗

  27. Function evaluation function F = myfun2(x) F(1) = 2*x(1).^2 + x(2)^2-24; F(2) = x(1).^2 - x(2).^2+12; return 軟體實作與計算實驗

  28. Find a zero x0= ones(1,2)*2; x = lsqnonlin(@myfun2,x0) y=myfun2(x); sum(y.^2) CHECKING 軟體實作與計算實驗

  29. Multiple roots v=[] for i=1:n x0= ones(1,2)*2; x = lsqnonlin(@myfun2,x0) v=[v;x]; plot(x(1),x(2),'o'); 軟體實作與計算實驗

  30. x=linspace(-5,5); plot(x,sqrt(24-2*x.^2),'r');hold on; plot(x,-sqrt(24-2*x.^2),'r') plot(x,sqrt(12+x.^2),'b') plot(x,-sqrt(12+x.^2),'b') 軟體實作與計算實驗

  31. Demo_lsq_2c source code 軟體實作與計算實驗

  32. 軟體實作與計算實驗

  33. Function evaluation function F = myfun3(x) F(1) = x(1).^2 -2* x(2)^2-2; F(2) = x(1).*x(2) -2; return 軟體實作與計算實驗

  34. x=linspace(-3,3); x=x(find(abs(x) > 0.1)); plot(x,sqrt((x.^2-2)/2),'r');hold on; plot(x,-sqrt((x.^2-2)/),'r') x=linspace(0.5,3); plot(x,2./x,'b'); x=linspace(-0.5,-3); plot(x,2./x,'b') 軟體實作與計算實驗

  35. Find a zero x0= ones(1,2)*2; x = lsqnonlin(@myfun3,x0) y=myfun3(x); sum(y.^2) CHECKING 軟體實作與計算實驗

  36. Multiple roots v=[] for i=1:n x0= ones(1,2)*2; x = lsqnonlin(@myfun3,x0) v=[v;x]; plot(x(1),x(2),'o'); 軟體實作與計算實驗

  37. demo_lsq_hyperbola.m two_hyperbola.m 軟體實作與計算實驗

  38. Matrix Multiplication • C=A*B • C(i,j)=A(i,:) *B(:,j) for all i,j 軟體實作與計算實驗

  39. Nested FOR Loops [n,d1]=size(A);[d2,m]=size(B) for i=1:n for j=1:m C(i,j)=A(i,:) *B(:,j) 軟體實作與計算實驗

  40. [n,d1]=size(A);[d2,m]=size(B); for i=1:n for j=1:m C(i,j)=A(i, :) *B(:,j); end end 軟體實作與計算實驗

  41. Constrained optimization Inequality constraint Nonlinear equality 軟體實作與計算實驗

  42. Constrained optimization 軟體實作與計算實驗

  43. Constraints • Lower bound and upper bound • Equality constraint • Inequality constraint 軟體實作與計算實驗

  44. Constraints Lower bound Upper bound Inequality constraints 軟體實作與計算實驗

  45. Demo_conop2 demo_conop2.m function demo_conop2() lb =[-2 0]; ub =[10,10]; Aeq=[-1 1];beq=[0]; A=[];b=[]; x = fmincon(@fun,[1 1],A,b,Aeq,beq,lb,ub) x(1).^2+x(2).^2 return function y = fun(x) y = (x(1).^2+x(2).^2-13).^2; return 軟體實作與計算實驗

  46. Objective function function y = fun(x) y = (x(1).^2+x(2).^2-13).^2; return 軟體實作與計算實驗

  47. Calling fmincon x = fmincon(@fun,[1 1],A,b,Aeq,beq,lb,ub) objective function initial guess linear equality inequality Lower and upper bound 軟體實作與計算實驗

  48. Random variable • Sample space S={A,T,C,G} • X is a discrete random variable with sample space S. 軟體實作與計算實驗

  49. Flip-flop pa pt pg pc T C G A Generative model gatcacaggt 軟體實作與計算實驗

  50. Partition 0 1 Knots partition [0,1] into four intervals respectively with lengths, 軟體實作與計算實驗

More Related