

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This is solution to one of problems in Numerical Analysis. This is matlab code. Its helpful to students of Computer Science, Electrical and Mechanical Engineering. This code also help to understand algorithm and logic behind the problem. This code includes: Range, Kutta, System, Differential, Equations, Algorithm, Solution, Initial, Conditions, Value, Problem, Endpoints
Typology: Exercises
1 / 3
This page cannot be seen from the preview
Don't miss anything!


syms('OK', 'M', 'I', 'A', 'B', 'ALPHA', 'N', 'FLAG'); syms('NAME', 'OUP', 'H', 'T', 'J', 'W', 'L', 'K','s'); syms('K1','K2','K3','K4','Z'); TRUE = 1; FALSE = 0; fprintf(1,'This is the Runge-Kutta Method for Systems of m equations\n'); fprintf(1,'This program uses the file F.m. If the number of equations\n'); fprintf(1,'exceeds 7, then F.m must be changed.\n'); OK = FALSE; while OK == FALSE fprintf(1,'Input the number of equations\n'); M = input(' '); if M <= 0 fprintf(1,'Number must be a positive integer\n'); else OK = TRUE; end; end; for I = 1:M fprintf(1,'Input the function F_(%d) in terms of t and y1 ... y%d\n', I,M); fprintf(1,'For example: y1-t^2+1 \n'); s(I) = input(' ','s'); end; OK = FALSE; while OK == FALSE fprintf(1,'Input left and right endpoints on separate lines.\n'); A = input(' '); B = input(' '); if A >= B fprintf(1,'Left endpoint must be less than right endpoint\n'); else OK = TRUE; end; end; ALPHA = zeros(1,M); for I = 1:M fprintf(1,'Input the initial condition alpha(%d)\n', I); ALPHA(I) = input(' '); end;
while OK == FALSE fprintf(1,'Input a positive integer for the number of subintervals\n'); N = input(' '); if N <= 0 fprintf(1,'Number must be a positive integer\n'); else OK = TRUE; end; end; if OK == TRUE fprintf(1,'Choice of output method:\n'); fprintf(1,'1. Output to screen\n'); fprintf(1,'2. Output to text file\n'); fprintf(1,'Please enter 1 or 2\n'); FLAG = input(' '); if FLAG == 2 fprintf(1,'Input the file name in the form - drive:\name.ext\n'); fprintf(1,'For example A:\OUTPUT.DTA\n'); NAME = input(' ','s'); OUP = fopen(NAME,'wt'); else OUP = 1; end; fprintf(OUP,'RUNGE-KUTTA METHOD FOR SYSTEMS OF DIFFERENTIAL EQUATIONS\n\n'); fprintf(OUP, ' T'); for I = 1:M fprintf(OUP, ' W%d', I); end; % STEP 1 W = zeros(1,M); V = zeros(1,M+1); K1 = zeros(1,M); K2 = zeros(1,M); K3 = zeros(1,M); K4 = zeros(1,M); H = (B-A)/N; T = A; % STEP 2 for J = 1:M W(J) = ALPHA(J); end; % STEP 3 fprintf(OUP, '\n%5.3f', T); for I = 1:M fprintf(OUP, ' %11.8f', W(I)); end; fprintf(OUP, '\n'); % STEP 4 for L = 1:N % STEP 5 V(1) = T; for J = 2:M+