LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (https://www.linuxquestions.org/questions/general-10/)
-   -   math program that I can enter math functions ... (https://www.linuxquestions.org/questions/general-10/math-program-that-i-can-enter-math-functions-436212/)

Four 04-17-2006 08:51 PM

math program that I can enter math functions ...
 
Whats language (I know c++, and some others) (I prefer interpreted and free for speed of "seeing") or program that I can enter functions in it, and have compositions of functions, and able to call a function like
F(3)
and it would tell me the value there.

Thanks!

Simon Bridge 04-17-2006 09:00 PM

You want octave

this is a math script language similar to mathematica and matlab only it is GPL.

It is available from repositories if you run a debian or rpm based distribution. (Please edit your profile to show your location and distribution, thanks.)

primo 04-19-2006 02:42 AM

Try bc(1). The manual:
http://www.gnu.org/software/bc/manual/bc.html

Leha208 04-19-2006 08:31 AM

Hi!
I am new to here. My friend show me this useful website. I hope anyone here could help me out. Ive tried to learn MATLAB. When i test it with my lecturer's file, i didnt score full mark. Please guide me through.
build-in function-functask2=sinh(x)-x.^2+x+1, xvalues=[1x50 double].
1) i need to compute the function at these xvalues and store in yvalues.
2) find best fit,quadratic n cubic to these values. Store the polynomial coefficient in linecoef, quadcoef and cubiccoef.
3) find new vector of x values,xnew,where there are 5 equispaced points betw each of the values in xvalues.
4) evaluate the polynomials and the function at xnew, store in yline, yquad, ycubic and yfunc.
5) do a cubic spline interpolation betw xvalues, yvalues, to find output values ynew at xnew.
6) overlay all 5 curves in a single plot.

my file is:
function out2=task2(in2)

%%% Compute what is originally in the workspace for task2.
out2=in2;

%%% Let x be a cell array containings the xvalues.
%%% Evaluate the function at x and compute them
%%% in yvalues.
x=in2.xvalues;
out2.yvalues=eval(in2.functask2);

%%% Compute the best fit straightline,
%%% quadractic and cubic to those yvalues.
%%%
out2.linecoef= polyfit(x,out2.yvalues, 1);
out2.quadcoef=polyfit(x,out2.yvalues,2);
out2.cubiccoef=polyfit(x,out2.yvalues,3);
r=numel(x);
xnew=linspace(x(1),x(end),6*(r-1)+ 1);
out2.xnew=xnew;
out2.yline=polyval(out2.linecoef,xnew);
out2.yquad=polyval(out2.quadcoef,xnew);
out2.ycubic=polyval(out2.cubiccoef,xnew);
x = xnew;
out2.yfunc=eval(in2.functask2,xnew);
ynew=spline(in2.xvalues, out2.yvalues, x);
out2.ynew=ynew;
figure(2); clf reset;
plot(xnew,ynew,'b', xnew,out2.yline, 'g',...
xnew,out2.yquad, 'y', xnew, out2.ycubic, 'k',...
xnew, out2.yfunc, 'm');
title( in2.functask2);
legend('vector', 'best fit line', 'quadratic',...
'cubic', 'function');


My up-2-date file is:
function out2=task2(in2)
out2=in2;
x=in2.xvalues;
out2.yvalues=eval(in2.functask2);

% To find the best fit straightline, quadratic
% and cubic at yvalues.
% Store them as polynomial coefficients in linecoef,
% quadcoef and cubiccoef respectively.
out2.linecoef= polyfit(x,out2.yvalues, 1);
out2.quadcoef=polyfit(x,out2.yvalues,2);
out2.cubiccoef=polyfit(x,out2.yvalues,3);

% To find a new vector, xnew.
% xnew contains values in x.
% xnew has 5 equispaced points between
% each of the values in x.
[x_val,y_val]= size(x);
% x_val the number of rows and y_val the number
% of columns in x.
aa=cell(1,(y_val-1));
% creates a 1-by-(y_val-1) cell array of empty matrices.
for i=1:(y_val-1)
if i==1
aa{i}=linspace(x(i),x(i+1),7);
else % if i is not equal to 1
xx=linspace(x(i),x(i+1),7);
xxx=xx(2:end);
aa{i}=xxx;
end
end
xnew=[aa{1:end}];
out2.xnew=xnew;
% To evaluate the polynomials and functask2 at xnew.
% store them in yline, yquad, ycubic and yfunc
% respectively.
out2.yline=polyval(out2.linecoef,xnew);
out2.yquad=polyval(out2.quadcoef,xnew);
out2.ycubic=polyval(out2.cubiccoef,xnew);
x = xnew;
out2.yfunc=eval(in2.functask2,xnew);

% To perform cubic spline interpolation between
% xvalues and yvalues.
% computes the values at xnew and store them at ynew.
ynew=spline(in2.xvalues, out2.yvalues, xnew);
out2.ynew=ynew;
% To plot a graph on figure(2) showing the 5 curves.
figure(2); clf reset;
plot(xnew,out2.ynew,'b', xnew,out2.yline, 'g',...
xnew,out2.yquad, 'y', xnew, out2.ycubic, 'k',...
xnew, out2.yfunc, 'm');
title(in2.functask2);
legend('vector', 'best fit line', 'quadratic',...
'cubic', 'function');
cheers!! please help me out.

ZUs.

truthfatal 04-19-2006 12:34 PM

Maple is my favorite Math Program.

I don't know about languages though -- to me saying math language is the same as saying Math. you learn that in grade two :p

Simon Bridge 04-19-2006 08:02 PM

Leha208: we are not here to do your homework for you. Why don't you post to me privately, and show me how you tried to do this. Then, maybe I can give you some pointers.

Otherwise, there are plenty of matlab tutorials online.


All times are GMT -5. The time now is 07:17 AM.