diff options
author | Chayan Bhawal | 2018-09-28 08:30:22 +0530 |
---|---|---|
committer | Chayan Bhawal | 2018-09-28 08:30:22 +0530 |
commit | f91b28ce516ae287fbaac390cde07c7f7a9aca97 (patch) | |
tree | 1d13f70670e94b9199c389d23034e2c0e01c8678 | |
parent | 032dc034194100cb3428d073efd0a8ed05c3accd (diff) | |
download | scilab-tutorials-f91b28ce516ae287fbaac390cde07c7f7a9aca97.tar.gz scilab-tutorials-f91b28ce516ae287fbaac390cde07c7f7a9aca97.tar.bz2 scilab-tutorials-f91b28ce516ae287fbaac390cde07c7f7a9aca97.zip |
Tutorial4_ODE_solvers
5 files changed, 63 insertions, 4 deletions
diff --git a/Tutorial4_ODE/Scilab_code/Tutorial4_ode_matrix.sce b/Tutorial4_ODE/Scilab_code/Tutorial4_ode_matrix.sce new file mode 100644 index 0000000..fff34eb --- /dev/null +++ b/Tutorial4_ODE/Scilab_code/Tutorial4_ode_matrix.sce @@ -0,0 +1,19 @@ +//This script demonstrates the use of ODE solver when matrix is involved + +//Definition of the function +function ydot = func(t,y) + ydot = A*y + ones(3,1); +endfunction + +//Defining the matrix +A = [1 2 1;9 6 1;1 3 4]; +//Initial condition +y0 = [-1;2;3]; +//Start time +t0= 0; +//The time at which the solution is computed +t = 0.2; +//Calling the ode solver +sol=ode(y0,t0,t,func); +//Displaying the solution +disp(sol,"y(t) at t = 0.2"); diff --git a/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple.sce b/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple.sce new file mode 100644 index 0000000..ad42d4d --- /dev/null +++ b/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple.sce @@ -0,0 +1,19 @@ +//This script demonstrates the use of ODE solver + +//Definition the function. +//The function is dy/dt = cos(t)*sin(t) - tan(t) + 1 +function ydot = func(t,y) + ydot = cos(t)*sin(t) - tan(t) + 1 +endfunction + +//Initial condition of the problem, a scalar or vector +y0 = -1; +//Initial time, a real scalar +t0= 0; +//The time at which the solution is computed +t = 0.2; +//Calling the ode solver +sol=ode(y0,t0,t,func); +//Displaying the solution +disp(sol,"y(t) at t = 0.2"); + diff --git a/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple_plot.sce b/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple_plot.sce new file mode 100644 index 0000000..4ecf87e --- /dev/null +++ b/Tutorial4_ODE/Scilab_code/Tutorial4_ode_simple_plot.sce @@ -0,0 +1,19 @@ +//This script demonstrates the use of ODE solver and computing the +//solution at different times. The output is in the form of a plot +//of time versus computed solution + +//Definition the function. +function ydot = func(t,y) + ydot = t^2*exp(-2*t) + y +endfunction + +//Initial condition +y0 = -1; +//Start time +t0= 0; +//The array of time where the solution is computed +t = 4:0.01:10; +//Calling the ODE solver +sol=ode(y0,t0,t,func); +//Plotting the result +plot(t,sol) diff --git a/Tutorial5_Nonlinear_equation/Scilab_code/Tutotial5_nonlinear_equation.sce b/Tutorial5_Nonlinear_equation/Scilab_code/Tutotial5_nonlinear_equation.sce index 6d38c84..5da2894 100644 --- a/Tutorial5_Nonlinear_equation/Scilab_code/Tutotial5_nonlinear_equation.sce +++ b/Tutorial5_Nonlinear_equation/Scilab_code/Tutotial5_nonlinear_equation.sce @@ -5,16 +5,14 @@ clc //The nonlinear equation for which solutions are sought -function y = nonlinear_func(x) - y = cos(x)*sin(x) - tan(x) + 1 -endfunction +exec func.sci; //Initial guess for the solution x0 = 0; //Computation of solution using fsolve -y_result = fsolve(x0,nonlinear_func); +y_result = fsolve(x0,func); //Display the solution in command window disp(y_result,'Solution of the equation') diff --git a/Tutorial5_Nonlinear_equation/Scilab_code/func.sci b/Tutorial5_Nonlinear_equation/Scilab_code/func.sci new file mode 100644 index 0000000..91b9fcc --- /dev/null +++ b/Tutorial5_Nonlinear_equation/Scilab_code/func.sci @@ -0,0 +1,4 @@ +//This is script to define a fuction +function y = func(x) + y = cos(x)*sin(x) - tan(x) + 1 +endfunction |