Symbolic package: Difference between revisions

Jump to navigation Jump to search
1,062 bytes added ,  12 March 2019
m
(copy edit for demo)
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
The {{Forge|symbolic|symbolic package}} is part of the octave-forge project.
The {{Forge|symbolic|symbolic package}} is part of the [[Octave Forge]] project.


[[Category:Octave-Forge]]
[[Category:Octave Forge]][[Category:Packages]]


=== Demos and usage examples ===
=== Demos and usage examples ===
Line 31: Line 31:


  dfh (a)
  dfh (a)
ans = -1.5708


## And you can evaluate dfh at an array of "double" values:
## And you can evaluate dfh at an array of "double" values:


  dfh ([1.23 42.42 pi/2])
  dfh ([1.23 12.3 pi/2])
 
ans =
  -0.82502  4.20248  -1.57080
 
</source>
 
 
 
* '''Demo of how to graph symbolic functions (by converting SYMBOLIC functions into ANONYMOUS functions)'''
 
<source lang="octave">
 
## The following code will produce the same vector field plot as Figure 1.14 from Example 1.6 (pg. 39) from A Student's Guide to Maxwell's Equations by Dr. Daniel Fleisch.
 
## Make sure symbolic package is loaded and symbolic variables declared.
pkg load symbolic
syms x y
 
## Write a Vector Field Equation in terms of symbolic variables
vectorfield = [sin(pi*y/2); -sin(pi*x/2)];
 
## Vector components are converted from symbolic into "anonymous functions" which allows them to be graphed.
## The "'vars', [x y]" syntax ensures each component is a function of both 'x' & 'y'
iComponent = function_handle (vectorfield(1), 'vars', [x y]);
jComponent = function_handle (vectorfield(2), 'vars', [x y]);
 
## Setup a 2D grid
[X,Y] = meshgrid ([-0.5:0.05:0.5]);
 
figure
quiver (X, Y, iComponent (X, Y), jComponent (X,Y))


</source>
</source>
Line 126: Line 160:
  ##
  ##
  syms y(x)  
  syms y(x)  
  de =diff(y, 3 ) +sqrt(2)*diff(y,2) + diff(y) == 0;
sqrt2=sym(1.41421);
  de =diff(y, 3 ) +sqrt2*diff(y,2) + diff(y) == 0;
  f = dsolve(de, y(0) == 0, diff(y,1)(0) == 0 , diff(y,2)(0) == 1)
  f = dsolve(de, y(0) == 0, diff(y,1)(0) == 0 , diff(y,2)(0) == 1)
  ff=function_handle(rhs(f))
  ff=function_handle(rhs(f))

Navigation menu