{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4-element Array{Any,1}:\n", " #undef\n", " #undef\n", " #undef\n", " #undef" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tempvar = Array{Any}(undef,4)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4-element Array{Any,1}:\n", " \"Hello...word\"\n", " \"Hello...word\"\n", " \"Hello...word\"\n", " \"Hello...word\"" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fill!(tempvar, \"Hello...word\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4-element Array{Any,1}:\n", " \"Hello...word\"\n", " \"Hello...word\"\n", " \"Hello...word\"\n", " \"Hello...word\"" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tempvar" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4-element Array{Any,1}:\n", " 777\n", " 777\n", " 777\n", " 777" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fill!(tempvar,777)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "approxcos (generic function with 1 method)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function approxcos(x)\n", " outval = Array{Any}(undef,size(x))\n", " \n", " ii=0\n", " for aa in x\n", " y = 1 - aa^2/2 + aa^4/24 - aa^6/720 + aa^8/(56*720)\n", " ii = ii + 1\n", " outval[ii] = y\n", " end\n", " return outval\n", "end" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "x1 = 4*rand(10)\n", "\n", "x2 = range(0., stop=4., step=0.01)\n", "\n", "y1 = approxcos(x1)\n", "y2 = cos.(x2);" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Plots.GRBackend()" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using Plots\n", "gr()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scatter(x1,y1,legend=:false, title=\"Ilustrating 6-th order approximation to cos\")\n", "\n", "plot!(x2,y2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.2.0", "language": "julia", "name": "julia-1.2" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.2.0" } }, "nbformat": 4, "nbformat_minor": 4 }