Professional Documents
Culture Documents
Accepting Loop
Equations
We
use the input() function for accepting data from the user
Syntax:
Causing
Syntax:
for <array> loop body end
Note that you can also create the array as youre starting the loop
Example
f = 1; n = input(Enter number: ); for i=1:n f=f*i; end disp(The factorial is); disp(f);
Syntax:
while (<condition>) loop body variable iteration end
Same
f = 1; n = input(Enter a number: ); while(n>=1) f=f*n; n=n-1; end disp(Your answer is); disp(f);
A simultaneous equation is of the form: a1x + b1y = c1 a2x + b2y = c2 This can be written in matrix form as: AX = B Where A=[ a1,b1 ; a2,b2 ] , X=[ x ; y ] B=[ c1 ; c2 ]
This equation can be solved by taking: AX = B => X = A-1B So, our solution is:
X = inv(A)*B;
Refer
Apart
from the plot() function, for a 2D plot, we also have functions for plotting 3D surfaces. is done by the surf() and ezsurf() functions
This
Syntax:
surf( <2D array> ); OR surf(<1D x array>,<1D y array>,<2D array>);
Syntax:
syms <variable list>; ezsurf( <function> ); OR ezsurf(<function>,[<-xlim> <xlim> <ylim> <ylim>]);