Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriabarra committed Nov 13, 2024
1 parent 6334249 commit 123bad4
Show file tree
Hide file tree
Showing 13 changed files with 10,272 additions and 637 deletions.
48 changes: 48 additions & 0 deletions _sources/slides/module7-5_hw3_sol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 29) HW3 Solution

In this assignment we covered some of the topics of the Fortran programming language seen in class, such as some basic I/O.

We revisted an interpolation method seen in class, [Lagrange's interpolation method](https://sdsu-comp526.github.io/fall24/slides/module7-1_interpolation.html), and we learned how to _use_ Lagrange’s interpolating formula to approximate a function $f(x)$ over a domain $[a,b]$.

Remeber: Interpolation $\neq$ Function Approximation.

But we can _use interpolation_ to accurately _approximate_ continuous functions.


```{literalinclude} ../fortran_programs/midterm/main_lagrange.f90
:language: fortran
:linenos: true
```

## Extra Credit Question in Julia

The Fortran program above produced the appximating polynomial over a domain of 50 equally spaced points. Let's use Julia to read these values in, plot the original function $f(x)$, the approximating interpolating polynomial $p(x)$ and the discrete set of data points $(x_i,y_i)$.

```julia
using Plots
using LaTeXStrings
default(linewidth=4, legendfontsize=12)

s = 50
x_domain = LinRange(0,2,s)
p = zeros(length(x_domain))

f(x) = exp.(-3 .* x)

x_data = LinRange(0,2,5)
y_data = f.(x_data)

# open output.txt data and store values in the array called p
open("output.txt","r") do f
line = 1
while ! eof(f)
l = readline(f)
p[line] = parse.(Float64,l)
line += 1
end
end

# Plots
scatter(x_data,y_data, markersize = 6, label = L"(x_i, y_i)")
png(plot!(x_domain, [f.(x_domain) p ], linestyle = [:solid :dash], label = [" exp(-3x)" "p(x)"], title="Lagrange interpolation"), "lagrange_plot.png")
```
Loading

0 comments on commit 123bad4

Please sign in to comment.