תכנות נומרי עם Matlab ו-Octave/גרפים: הבדלים בין גרסאות בדף

תוכן שנמחק תוכן שנוסף
שומבלע (שיחה | תרומות)
העתקה מויקספר האנגלי ותחילת עבודה
 
שומבלע (שיחה | תרומות)
אין תקציר עריכה
שורה 1:
 
==גרפים דו-ממדיים==
===Plot===
plot היא פונקציה המקבלת קורדינאטות ב x ו y ומחזירה גרף. הגרף יפתח בחלון נפרד.
Plots a function in Cartesian Coordinates, x and y. <br>
דוגמא:
Example:
<source lang="matlab">
<pre>x=0:0.1:2; % creates a line vector from 0 to 2
fx=(x+2)./x.^2; % creates fx
plot(x,fx,'-ok') % plots 2d graphics of the function fx </pre>
</source>
 
כדי להדפיס 2 או יותר גרפים באותו תרשים, פשוט מוסיפים x,y נוספים לאחר הראשונים:
To plot 2 or more graphs in one Figure, then simply append the second (x,y) pair to the first:
 
>>>x1 = [1,2,3,4]
<source lang="matlab">
>>>x1 = [1,2,3,4]
>>>y1 = [1,2,3,4]
>>>y2 = [4,3,2,1]
>>>plot(x1,y1,x1,y2)
</source>
This will plot y1 and y2 on the same x-axis in the output.
הפקודה תדפיס y1 ו y2 על אותם קווי x
{{להשלים}}
 
===Polar===
Plots a function using θ and r(θ)
<source lang="matlab">
<pre>t = 0:.01:2*pi;
polar(t,sin(2*t).^2) </pre>
</source>
 
==גרפים תלת-מימדיים==
 
שורה 26 ⟵ 34:
 
Example:
<source lang="matlab">
<pre>
l=[-98.0556 ; 1187.074];
f=[ -33.5448 ; -240.402];
d=[ 1298 ; 1305.5]
plot3(l,f,d); grid on;
</presource>
 
 
 
This example plots a line in 3d. I created this code in an M-file. If you do the same you change the values and hit the run button in the menu bar to see the effect.
שורה 39 ⟵ 49:
 
Example:
<source lang="matlab">
<pre>
x=[0:pi/90:2*pi]';
y=x';
z=sin(x*y);
mesh(x,y,z);
</presource>
 
 
===Contour===
שורה 50 ⟵ 61:
 
Example:
<source lang="matlab">
<pre>
x=[0:pi/90:2*pi]';
y=x';
z=sin(x*y);
contour(x,y,z);
</presource>
 
 
===Contourf===
Same as contour, but fills color between contour lines