In addition to my R programming course, I am also taking an intro to LaTeX course. We have a new assignment which is to generate a graph of a given function (in Matlab), save it and then recall it in LaTeX code as though we're making a publication. My Matlab is a little rusty, and I don't think that I quite got the code right. Furthermore it doesn't look anything like the example we were given for reference. The function that we were asked to plot is the following: 1 = x^(2)/9 - y^(2)/4
What my image is supposed to look like:
What my Matlab code generated:
function graph_1
clc; clear all;
a = 9;
b = 4;
x0 = 0;
y0 = 0;
t = -pi:0.1:pi;
x = 1 - x0 + a*cos(t);
y = 1 - y0 + a*sin(t);
figure(1); clf;
plot(x,y,'b','linewidth',1)
set(gca, 'fontsize', 12)
xlabel('X')
ylabel('Y')
grid on
end
Once I get the code to run in Matlab, I get a weird looking ellipse and it doesn't look "pretty" like the one my professors gave us as reference which I have attached. The full assignment is asking us to generate a plot with our programming language of choice, save it, and then have the LaTeX code actually recall the file and then insert into a pdf. How would I export this figure to somehwere else in my computer?
b
in your computation. (2) Yourt
doesn't end with the same angle it starts with, hence the gap; uselinspace
instead. (3) Addaxis equal
after plotting so that the aspect ratio is correct. (4) Useprint
to export as PDF (check the docs). (5) Don't ever useclear all
, but especially not inside a function!clear
by itself clears all variables, but at the start of your function you don't have any variables to clear. - Cris Luengoa=9
, should probably be 3. - Cris Luengohelp linspace
to get documentation, ordoc linspace
to get more elaborate documentation. Or just look online: mathworks.com/help/matlab/ref/linspace.html - Cris Luengo