Skip to content

Instantly share code, notes, and snippets.

@Observatorio-de-Matematica
Created January 5, 2024 18:05
Show Gist options
  • Save Observatorio-de-Matematica/11bbd98efd2e1b11c32553f0ff9fb766 to your computer and use it in GitHub Desktop.
Save Observatorio-de-Matematica/11bbd98efd2e1b11c32553f0ff9fb766 to your computer and use it in GitHub Desktop.
/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/
/* [ Created with wxMaxima version 0.8.3 ] */
/* [wxMaxima: title start ]
2301560 Comp Tools Math
September 4, 2009
[wxMaxima: title end ] */
/* [wxMaxima: section start ]
Graphics
[wxMaxima: section end ] */
/* [wxMaxima: fold start ] */
/* [wxMaxima: subsect start ]
Simple 2D Plots
[wxMaxima: subsect end ] */
/* [wxMaxima: fold start ] */
/* [wxMaxima: input start ] */
plot2d(sin(x)/x,[x,-6*%pi,6*%pi]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
plot2d(sin(x)/x,[x,-6*%pi,6*%pi],[y,-1.2,1.2],
[xlabel,"x label here"],[ylabel,"y label here"],[box,false]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
plot2d(sin(x)/x,[x,-6*%pi,6*%pi],[psfile,"fig1.ps"]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
plot2d([sin(x),cos(x)],[x,-2*%pi,2*%pi],[legend,"sine","cosine"]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
my_preamble: "set xtics ('-2{/Symbol p}' -6.283,\
'-3{/Symbol p}/2' -4.712, '-{/Symbol p}' -3.1415, \
'-{/Symbol p}/2' -1.5708, '0' 0,'{/Symbol p}/2' 1.5708, \
'{/Symbol p}' 3.1415,'3{/Symbol p}/2' 4.712, '2{/Symbol p}' 6.283)"$
plot2d ([cos(x), sin(x), tan(x)], [x, -2*%pi, 2*%pi],
[y, -2, 2], [gnuplot_preamble, my_preamble],[psfile,"fig2.ps"]);
/* [wxMaxima: input end ] */
/* [wxMaxima: fold end ] */
/* [wxMaxima: subsect start ]
2D List Plots
[wxMaxima: subsect end ] */
/* [wxMaxima: fold start ] */
/* [wxMaxima: input start ] */
data1:makelist([x/50,sin(x)],x,-500,500)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
plot2d([discrete,data1],[style,[points,0.5,0,1]]);
/* [wxMaxima: input end ] */
/* [wxMaxima: fold end ] */
/* [wxMaxima: subsect start ]
2D Parametric Plots
[wxMaxima: subsect end ] */
/* [wxMaxima: fold start ] */
/* [wxMaxima: input start ] */
plot2d([parametric,cos(t),sin(t),[t,0,2*%pi],[nticks,200]],[x,-4/3,4/3]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
plot2d([parametric,cos(t),sin(t),[t,0,2*%pi],[nticks,4]],[x,-4/3,4/3]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
plot2d([parametric,cos(3*t),sin(5*t),[t,0,2*%pi],[nticks,1000]],[x,-1.2,1.2],[y,-1.2,1.2]);
/* [wxMaxima: input end ] */
/* [wxMaxima: fold end ] */
/* [wxMaxima: subsect start ]
Implicit Plots
[wxMaxima: subsect end ] */
/* [wxMaxima: fold start ] */
/* [wxMaxima: input start ] */
load(implicit_plot);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
implicit_plot(x^2 - y^2 = 1, [x, -4, 4], [y, -4, 4]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
implicit_plot(makelist(x^2 - y^2 = i,i,1,5), [x, -4, 4], [y, -4, 4],
[gnuplot_preamble,"unset key; set zeroaxis"]);
/* [wxMaxima: input end ] */
/* [wxMaxima: fold end ] */
/* [wxMaxima: subsect start ]
Contour Plots
[wxMaxima: subsect end ] */
/* [wxMaxima: fold start ] */
/* [wxMaxima: input start ] */
contour_plot(x^2-y^2,[x,-10,10],[y,-10,10]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
set_plot_option([gnuplot_preamble,
"set cntrparam levels incremental -100,10,100;unset clabel;unset key"])$
contour_plot(x^2-y^2,[x,-10,10],[y,-10,10]);
/* [wxMaxima: input end ] */
/* [wxMaxima: fold end ] */
/* [wxMaxima: subsect start ]
Gradient Fields
[wxMaxima: subsect end ] */
/* [wxMaxima: fold start ] */
/* [wxMaxima: input start ] */
load(plotdf);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
plotdf(y-0.1*x^2/10,[trajectory_at,2,0.9]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
plotdf(a*y+b*x^2/10+c,[trajectory_at,2,0.9],[sliders,"a=-10:10,b=0.1:4,c=-5:5"]);
/* [wxMaxima: input end ] */
/* [wxMaxima: fold end ] */
/* [wxMaxima: subsect start ]
3D Plots
[wxMaxima: subsect end ] */
/* [wxMaxima: fold start ] */
/* [wxMaxima: input start ] */
plot3d (2^(-u^2 + v^2), [u, -3, 3], [v, -2, 2]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
plot3d (2^(-u^2 + v^2), [u, -3, 3], [v, -2, 2],[plot_format, openmath]);
/* [wxMaxima: input end ] */
/* [wxMaxima: fold end ] */
/* [wxMaxima: subsect start ]
3D Parametric Plots
[wxMaxima: subsect end ] */
/* [wxMaxima: fold start ] */
/* [wxMaxima: input start ] */
plot3d([sin(u)*cos(v),sin(u)*sin(v),cos(u)],[u,0,%pi],[v,0,2*%pi]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
plot3d([u*cos(v),u*sin(v),u^2],[u,0,3],[v,0,2*%pi]);
/* [wxMaxima: input end ] */
/* [wxMaxima: fold end ] */
/* [wxMaxima: subsect start ]
Draw
[wxMaxima: subsect end ] */
/* [wxMaxima: fold start ] */
/* [wxMaxima: input start ] */
load(draw);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
draw2d(
ellipse(0,0,1,1,0,360),
transparent=true,
color = blue,
line_width = 4,
ellipse(0,0,2,1/2,0,360),
proportional_axes = xy) $
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
draw2d(
explicit(sin(x),x,0,10),
yaxis_secondary = true,
ytics_secondary = true,
yrange = [-3, 3],
yrange_secondary = [-20, 20],
color = blue,
explicit(100*sin(x+0.1)+2,x,0,10));
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
draw3d(yrange = [-3,3],
zrange = [-2,5],
explicit(x^2+y^2,x,-1,1,y,-1,1),
xrange = [-3,3])$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
draw3d (
enhanced3d = true,
color = green,
cbrange = [-3,10],
explicit(x^2+y^2, x,-2,2,y,-2,2));
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
draw(
delay = 100,
file_name = "fig3",
terminal = 'animated_gif,
gr2d(explicit(x^2,x,-1,1)),
gr2d(explicit(x^3,x,-1,1)),
gr2d(explicit(x^4,x,-1,1)));
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
draw2d(xrange = [0,10],
yrange = [0,10],
point_size = 3,
point_type = diamant,
points([[1,1],[5,1],[9,1]]),
point_type = filled_down_triangle,
points([[1,2],[5,2],[9,2]]),
point_type = asterisk,
points([[1,3],[5,3],[9,3]]),
point_type = filled_diamant,
points([[1,4],[5,4],[9,4]]),
point_type = 5,
points([[1,5],[5,5],[9,5]]),
point_type = 6,
points([[1,6],[5,6],[9,6]]),
point_type = filled_circle,
points([[1,7],[5,7],[9,7]]),
point_type = 8,
points([[1,8],[5,8],[9,8]]),
point_type = filled_diamant,
points([[1,9],[5,9],[9,9]]) );
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
x: make_array (fixnum, 10) $
y: make_array (fixnum, 10) $
z: make_array (fixnum, 10) $
for i:0 thru 9 do (
x[i]: random(10),
y[i]: random(10),
z[i]: random(10) ) $
draw3d(points(x,y,z));
/* [wxMaxima: input end ] */
/* [wxMaxima: fold end ] */
/* [wxMaxima: fold end ] */
/* [wxMaxima: section start ]
Curve Fitting
[wxMaxima: section end ] */
/* [wxMaxima: fold start ] */
/* [wxMaxima: input start ] */
load(lsquares);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
data1_list:makelist([x,2*x+3+random(1.0)],x,-5,5)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
plot2d([discrete,data1_list],[style,[points,2,2,1]]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
data1_matrix:apply('matrix,data1_list)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
param1:lsquares_estimates(data1_matrix, [x,y], y = a*x+b, [a,b]);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
plot2d([[discrete,data1_list],subst(param1[1],a*x+b)],[x,-5,5],
[style, [points,2,2,1], [lines,1,1]],
[legend,"data","least squares fit"]);
/* [wxMaxima: input end ] */
/* [wxMaxima: fold end ] */
/* [wxMaxima: section start ]
Exercise
[wxMaxima: section end ] */
/* [wxMaxima: fold start ] */
/* [wxMaxima: comment start ]
Prob 1. Let Tn(x) be the Taylor polynomial of degree n of cos x about the point 0.
Plot cos(x) along with T2(x), T4(x), T6(x), and T8(x).
Set an appropriate range of the plot to reveal how well the Taylor polynomials
approximate the function. The Taylor polynomials should be automatically generated.
[wxMaxima: comment end ] */
/* [wxMaxima: comment start ]
Prob 2. Plot the polar curve r = 1+4sin(theta/3).
[wxMaxima: comment end ] */
/* [wxMaxima: comment start ]
Prob 3. Plot the surface of revolution generated by y = x^2, 0 < x < 1
about each of the following axes.
3.1 The x axis.
3.2 The y axis.
3.3 The line y = x.
[wxMaxima: comment end ] */
/* [wxMaxima: comment start ]
Prob 4. Generate the following data
[x, (1+random(1.0)) x^4 + random(1.0)x]
where x = -1.00, -0.95, -0.90, ..., 1.00.
Then fit each of the following models to the this set of data.
You should make some plots to show how well the model fits to the data.
4.1 y = ax^4 + bx^3 + cx^2 + dx + e.
4.2 y = ax^4 + bx.
[wxMaxima: comment end ] */
/* [wxMaxima: comment start ]
Prob 5. Fit the following data with an appropriate model.
[x, x + (4 + random(1.0))sin(x) + (1+random(1.0))sin(5x)]
where x = 0.0, 0.1, 0.2, ..., 10.0
.
[wxMaxima: comment end ] */
/* [wxMaxima: fold end ] */
/* Maxima can't load/batch files which end with a comment! */
"Created with wxMaxima"$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment