download barcode font for vb.net Numerical Solution of ODEs in Visual Studio .NET

Generator QR in Visual Studio .NET Numerical Solution of ODEs

CHAPTER 7 Numerical Solution of ODEs
Quick Response Code Encoder In Visual Studio .NET
Using Barcode generator for Visual Studio .NET Control to generate, create Quick Response Code image in .NET applications.
Read Quick Response Code In Visual Studio .NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in VS .NET applications.
4 35 3 25 y(t) 2 15 1 05 0
Printing Bar Code In VS .NET
Using Barcode encoder for .NET Control to generate, create bar code image in .NET applications.
Scanning Bar Code In .NET Framework
Using Barcode decoder for VS .NET Control to read, scan read, scan image in .NET applications.
Figure 7-1
Drawing Quick Response Code In Visual C#.NET
Using Barcode creation for VS .NET Control to generate, create Quick Response Code image in .NET applications.
QR Code Drawer In .NET
Using Barcode generator for ASP.NET Control to generate, create QR Code image in ASP.NET applications.
Plot showing numerical and analytical solutions of
Quick Response Code Printer In VB.NET
Using Barcode drawer for .NET framework Control to generate, create QR Code 2d barcode image in VS .NET applications.
Generating GS1 DataBar Limited In .NET Framework
Using Barcode encoder for .NET framework Control to generate, create GS1 DataBar image in VS .NET applications.
dy = cos(t ) dt
Code 39 Drawer In .NET
Using Barcode drawer for Visual Studio .NET Control to generate, create Code 39 Extended image in .NET applications.
Barcode Encoder In VS .NET
Using Barcode maker for Visual Studio .NET Control to generate, create barcode image in Visual Studio .NET applications.
Now we calculate the relative error at each point by using a for loop to move through the data:
Generating Code-128 In .NET
Using Barcode encoder for VS .NET Control to generate, create Code 128 image in .NET applications.
Encode Leitcode In .NET
Using Barcode maker for .NET framework Control to generate, create Leitcode image in Visual Studio .NET applications.
>> for i = 1:1:size(y) err(i) = abs((f(i) y(i))/f(i)); end
ECC200 Creation In None
Using Barcode generation for Font Control to generate, create Data Matrix 2d barcode image in Font applications.
Generate GTIN - 128 In None
Using Barcode drawer for Office Word Control to generate, create EAN128 image in Office Word applications.
Let s look at the result:
EAN-13 Generation In C#.NET
Using Barcode encoder for VS .NET Control to generate, create EAN / UCC - 13 image in VS .NET applications.
Barcode Reader In Visual Studio .NET
Using Barcode Control SDK for ASP.NET Control to generate, create, read, scan barcode image in ASP.NET applications.
>> err err = 10e 003 * 0 00001 00091 00301 00743 02115 02876 03780 04659
Drawing UPC-A In Java
Using Barcode drawer for Eclipse BIRT Control to generate, create UCC - 12 image in BIRT reports applications.
Make European Article Number 13 In None
Using Barcode generator for Software Control to generate, create EAN13 image in Software applications.
MATLAB Demysti ed
GS1 - 12 Creation In None
Using Barcode creation for Office Word Control to generate, create GTIN - 12 image in Office Word applications.
Paint UPC - 13 In Java
Using Barcode drawer for Java Control to generate, create EAN / UCC - 13 image in Java applications.
05597 06480 06907 06050 04533 03164 02414 02129
The errors are quite small in this case The largest error is:
>> emax = max(err) emax = 69075e 004
Let s look at the data points returned by the ode23 solver:
y = 20000 21593 25110 28080 29848 29169 26344 22123 17999 14512 11892 10323 10115 11536 14337 17689 19996
With the precision used to present these numbers, since the relative error is much smaller, we can be satis ed with the results The ode45 function uses higher order Runge-Kutta formulas Let s see how it works differently in the case we are currently working with The call is similar:
>> [t,w] = ode45('eq1',[0 2*pi],2);
CHAPTER 7 Numerical Solution of ODEs
However, the solution is evaluated over a larger number of points So we need to regenerate the analytical solution, then let s plot them both:
>> f = 2 + sin(t); >> plot(t,w,'o',t,f),xlabel('t'),ylabel('y(t)'),axis([0 2*pi 0 4])
The result is shown in Figure 7-2 You can see that the density of points from the numerical solution is higher than what we got with ode23 Let s compare the sizes of the solutions:
>> size(w),size(y) ans = 45 ans = 1 1
The ode45 solver has returned 45 data points while the ode23 solver returned 17 data points Whether this is important or not will depend on your application Let s create another array of zeros and calculate the relative error:
>> err = zeros(size(w)); >> for i = 1:1:size(w) err(i) = abs((f(i) w(i))/f(i)); end
4 35 3 25 y(t) 2 15 1 05 0
Figure 7-2
Solving the equation again with ode45
Let s nd the maximum relative error this time:
>> wmax = max(err) wmax = 49182e 006
MATLAB Demysti ed
If you recall, the maximum error we found with the ode23 solver was:
>> emax emax = 69075e 004
This is quite a bit larger than the maximum relative error obtained with ode45 In fact it s almost 141 times as big:
>> emax/wmax ans = 1404473
Hence it may be wise to use ode45, if the error differences are important Let s consider another example EXAMPLE 7-1 Consider the ordinary differential equation with forcing: dy = 5( F (t ) y) dt The forcing function is: F(t) = te t/tc cos(w t) Find and plot the numerical solution for the following values of the time constant tc and frequency shown in Table 7-1
CHAPTER 7 Numerical Solution of ODEs
Table 7-1 Time constant and frequency values for Example 7-1
Frequency 628 rad/s 628 rad/s
Time Constant 001 s 01 s
SOLUTION 7-1 To facilitate the ability to use several different values of the time constant and frequency, we will declare these as global values First let s write a function to implement the equation:
function ydot = eq2(t,y) global tc w F = t*exp(-t/tc)*cos(w*t); ydot = 5*F;
Following the procedure we used in the text, we code this function up in a m le and save it First we de ne our global variables (the time constant and frequency) in MATLAB:
>> global tc w
Now let s assign the rst values in the table:
>> tc = 001; w = 628;
Now let s set the end time of the interval we will evaluate together with the initial condition:
>> nal_time = 01; y0 = 0;
Next we call ode45 and generate the rst solution:
>> [t,y] = ode45('eq2',[0 nal_time],y0);
Let s plot the solution in Figure 7-3 Let s compare it with the forcing function:
>> plot(t,y,t,F,'--'),xlabel('t')
The forcing function is the dashed line As you can see in Figure 7-4, it is quite a bit larger than the response but it has a similar functional form In both cases we see an exponentially decaying oscillator
MATLAB Demysti ed
2 x10 5
0 y(t) 1 2 3 4
001 002 003 004 005 006 007 008 009 t
Figure 7-3
Copyright © OnBarcode.com . All rights reserved.