From owner-octave-sources at bevo dot che dot wisc dot edu Wed Apr 9 20:18:53 1997 Subject: funcplot function plotting routine From: Craig Earls To: octave-sources at bevo dot che dot wisc dot edu Date: Wed, 09 Apr 1997 21:18:38 -0400 Split the rest into two files, and mkoctfile on fpeval.cc **********************funcplot.m************************** ## usage: [data]=funcplot (Funcname,xvals,familyval...) ## ## Function named by Funcname, fplot will plot the function ## at each value in the vector xvals. Vector familyval will ## be passed to the function an element at a time and as its ## name implies can be used to plot a family of curves. ## ## Example: ## function out=functest(a,b) ## out=sin(a*b); ## endfunction ## ## funcplot("functest",[0:0.01:6.28],[1,2,3,4]); ## ## will plot four sin waves on the same plot with differing ## frequencies. The vector xvals must be a column or row, ## but may real or complex, the same requirements apply to ## familyvals. An arbitrary number of additional arguments ## may be passed the the function following familyvals. ## They will be passed as constants, and not varied between ## plots. ## ## funcplot requires fpeval.oct to run, and returns a matrix ## with the xvals in the first coumn and the coordinates for ## the curves in subsequent columns. ## Author: Craig Earls ## Description: Plot families of curves function out=funcplot(funcname,xvals,...) data=fpeval(funcname,xvals,all_va_args); lines=columns(data); out=data; clearplot; hold on; for i=2:lines gplot data using 1:i endfor hold off; endfunction *****************fpeval.cc********************************** /* Copyright (C) 1997 Craig p. Earls This file is an addition to Octave. Octave is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. Octave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Octave; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include ComplexMatrix res; octave_value_list arglist; ComplexMatrix fpeval_cycle (tree_fvc *fpeval_func, int numparms) { int lines,xind, points; ComplexColumnVector familyvals, xvals; octave_value_list Parameters,y; points=arglist(0).rows(); if(numparms>1){ lines=arglist(1).rows(); familyvals=arglist(1).complex_vector_value(); } else lines=1; xvals=arglist(0).complex_vector_value(); res.resize(points,lines+1,0.0); //copy the x values to the first column for(int i=0; i1) { Parameters.resize(2); Parameters(1)=familyvals(0); } if(numparms>2){ for (int i=2;i1) { Parameters(1)=familyvals(cind-1); } for(xind=0; xindeval (0, 1, Parameters); if (y.length () > 0 && y(0).is_defined ()) { res(xind,cind)=(y(0).complex_vector_value())(0); if (error_state) gripe_user_supplied_eval ("fpeval"); } else gripe_user_supplied_eval ("fpeval"); } } } return res; } DEFUN_DLD (fpeval, args, nargout, "Evaluates an arbitrary function to produce plots. Usage:\n\ \n\ [data]=fpeval(Funcname,Xvals,FamilsVals,...)\n\ \n\ fpeval will evaluate Funcname at each Xval,FamilyVal,\n\ as well as any further parameters. Xval must be a row or\n\ column vector, FamilyVals must be a row or column vector,\n\ additional arguments may be of any valid octave type, and \n\ will be passed unmodified.\n\ \n\ The first two arguments to Funcname must be scalars, and\n\ Funcname must return a scalar.\n\ \n\ This function is the guts of funcplot\n") { tree_fvc *fpeval_func; octave_value_list ret; int nargin; nargin = args.length (); if (nargin < 2 ) //nargout>1 { print_usage ("fpeval"); return res; } fpeval_func = is_valid_function (args(0), "fpeval", 1); if (! fpeval_func) return res; arglist.resize(1); arglist(0)=args(1).complex_vector_value(); if (nargin>2){ arglist.resize(2); arglist(1)=args(2).complex_vector_value(); } if (nargin>3){ arglist.resize(nargin); for(int i=3;i