Sometimes Matlab does not give you the result which you would expect. There are some peculiarities you have to be aware of.
format long gto see all computed digits, and to get scientific notation for each matrix element.
fprintf('The answer is %.15g\n',x)
e^x'' or ``
ln(x)'' I get strange results or errors
e^x. The natural logarithm function must be written as
ln(x). The base 10 logarithm is
x=0:.1:10; y1=sin(x); y2=cos(x);
ezplotdoes not show all of my plot
axis([xmin xmax ymin ymax])after the
orient landscape print test1.ps % save plot in file test1.ps
subplot(2,1,1) % divide page in 2 rows, 1 col, use 1st part ezplot('sin(x)',[-3 3]) % plot command for first graph subplot(2,1,2) % use 2nd part of divided page ezplot('x^2', [-3 3]) % plot command for second graph orient tall % make plot tall enough to fit whole page print test1.ps % save plot in file test1.ps
setcurve.min your home directory.
To change the curve color to red, use the following command after the
To change the curve color to green, use a dashed instead of a solid
line, and make the lines thicker, use the following command after the
help plot to see available line styles and
prob1.m, but when I type
prob1Matlab says it is undefined
If you are on a Unix machine you might save your m-file in the
/homes/myname/homework1 . At the Matlab command
>>" you should type
If you are on a Windows machine you might save your m-file in the
C:\My Documents\homework . At the Matlab command
prompt you should type
On WAM/Glue you should use
In the integrated environment you can also select in the "File" menu the item "Set Path...". Then use "Add Folder...", select a folder and hit "OK". Then click "Save", so that you do not have to do this again the next time you start Matlab.
%gfor each value you want to insert in the text, e.g.,
If you want to see e.g. 15 digits use
fprintf('The volume is %g, the area is %g\n',volume,area)
x = sqrt(1:6);
disp('The square roots are'); disp(x)
echo onand my m-file contains
for ... endthe commands in the loop get echoed many times
end'' with ``
echo off; end; echo on'' to supress echoing after the first loop iteration.
pausestatement after each plot command. Then Matlab will wait for you to press a key before moving on.
Method 2: put the statement
the first plot command,
figure(2) before the second plot
command etc. . This will generate a separate window for each plot.
hold onwith several plot commands in my m-file. I want to see what the graph looks like after each plotting command, but Matlab waits until the last plotting command before showing the graph.
drawnowafter each plotting command. This forces Matlab to update the graph immediately, rather than waiting until the end of the m-file.
while condition statements end
while 1 statements if condition break end statements end
See the Matlab help for