x <- seq(-5, 5, length = 100)
# Hint: Use the plot functionProblem set 1
After finishing the homework (10 points max), you are to turn in all the code to GitHub using git, described below.
- Start an RStudio Quarto project titled
p1. Place it inside a folder namedBIOSTAT620_pset_sol.
You will have two different types of .qmd files in this project: code files and an answer sheet. The code files will be used to run code for this assignment. The answer sheet will not run code, but you will input your answers to various questions.
Start a Quarto document called beginning.qmd (code file). This file will be used to run code for problems 3-4. We recommend you edit in source mode rather than visual.
Also copy this file pset-01-unix-quarto.qmd (answer sheet) and move it to the p1 directory. You will input some answers and code lines to this file.
(1 point) Create a directory called
imgand save a screen shot of your RStudio session for the project (titled img_2). Include your screenshot in the Quarto document.(1 point) Next, in your
beginning.qmdQuarto document, define variables \(a=1, b=-1, c=-2\) and print out the solutions to \(f(x) = ax^2+bx+c=0\). Solving the equation with the quadratic formula, do not report complex solutions, only real numbers.(1 point) Include in
beginning.qmda graph of \(f(x)\) versus \(x\) for \(x \in (-5,5)\).
Also include the x-axis (hint: use the lines function immediately after the plot function).
- (1 point) Create a directory called
docs. Use the commandquarto renderto create a PDF and save it to thedocsdirectory. Show us the command you typed:
# Your code here
- (1 point) Use Unix to create a directory called
datain the project home directory. Include the Unix command you used to create the directory. Also create aresultsdirectory in the home directory.
# Your code here
- (1 point) Use a terminal-based text editor to create a file
coefs1.txtin thedatadirectory and save three coefficients,1 -1 -2for example. Show us the Unix commands you used to achieve this:
# Your code here
- (1 point) Make a directory called
code. Use Unix to copy the filebeginning.qmdto a file calledquadratic.qmdin the code directory. Show us the Unix commands you used.
# Your code here
- (2 points) Edit the
quadratic.qmdfile to read ina,b, andcfrom the filecoefs.txt. Make sure to use a relative path when reading the file. As before, print out the solutions to \(f(x) = ax^2+bx+c=0\). Do not report complex solutions or duplicates, only real numbers. If no real solutions exist, output “no real solutions”.
Test your code on 3 different examples: coefs1.txt as above, coefs2.txt (a = -1, b = 2, c = -1), and coefs3.txt (a = -1, b = 1, c = -1) (note: you should create these files in data). In addition to printing, save the solutions in results/results{n}.txt as n ranges from 1 to 3. Hint: Generalize solve_quadratic as a function and run a for loop over the indices 1, 2, and 3.
- (1 point) Change the path of the file you are reading to the full path you get when you type
file.path(getwd(), "data/coefs.txt")(change thecoefs.txtfilename as appropriate). Confirm that the file still renders. Then move the entirep1project to a directory calledRtmpyDknq4. Does the file render? Change the path back to a relative path and see if it renders. Move your file back to the original directory when you are done.
# Your text response here. Does the file render with relative path? Does the file render with global hard-coded path?
- Navigate to
BIOSTAT620_pset_solin Terminal usingcd. Create a git instance by using:
git init
Add all files using:
git add .
Check the status using:
git status
Commit the files using:
git commit -m "pset1"
Create a new private repository on Github titled BIOSTAT620_pset_sol by clicking the New button and following instructions. On your local machine, add the Github remote url:
git remote add origin https://github.com/yourusername/BIOSTAT620_pset_sol.git
Push your commit to Github using:
git push origin main
Go to Github and check that your code has been added. Add Yize yhaoum as a collaborator to your Github private project.