matlab:matlab_examples
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
matlab:matlab_examples [2016/05/01 03:40] – created mithat | matlab:matlab_examples [2016/05/01 03:57] – mithat | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | [[http:// | + | ====== MATLAB m-file Examples ====== |
===== Simple script ===== | ===== Simple script ===== | ||
Line 16: | Line 16: | ||
===== Function m-file ===== | ===== Function m-file ===== | ||
+ | Ref.(((Recktenwald, | ||
<file matlab traparea.m> | <file matlab traparea.m> | ||
function area = traparea(a, b, h) | function area = traparea(a, b, h) | ||
Line 29: | Line 29: | ||
</ | </ | ||
- | ===== m-file with " | + | ===== m-files with " |
+ | Ref.(((Recktenwald, | ||
<file matlab compute_trapezoid.m> | <file matlab compute_trapezoid.m> | ||
function main | function main | ||
Line 45: | Line 45: | ||
% Compute the area, but suppress printing of the result | % Compute the area, but suppress printing of the result | ||
area = 0.5 * (a + b) * h; | area = 0.5 * (a + b) * h; | ||
+ | end | ||
+ | </ | ||
+ | |||
+ | Ref.((Unknown)) | ||
+ | <file matlab quads.m> | ||
+ | function main() | ||
+ | [root1, root2] = quadratic(1, | ||
+ | disp(root1); | ||
+ | disp(root2); | ||
+ | end | ||
+ | |||
+ | function [x1, x2] = quadratic(a, | ||
+ | % [x1, x2] = quadratic(a, | ||
+ | % Return the roots of a*x^2 + b*x + c. | ||
+ | % Roots may be complex. | ||
+ | |||
+ | d = disc(a, b, c); | ||
+ | x1 = (-b + d) / (2*a); | ||
+ | x2 = (-b - d) / (2*a); | ||
+ | end | ||
+ | |||
+ | function dis = disc(a, | ||
+ | % dis = disc(a,b,c) | ||
+ | % Return the discriminant of a, b, c. | ||
+ | dis = sqrt(b^2 - 4*a*c); | ||
end | end | ||
</ | </ | ||
===== Returning multiple values ===== | ===== Returning multiple values ===== | ||
+ | Ref.(((Recktenwald, | ||
<file matlab c_to_p.m> | <file matlab c_to_p.m> | ||
function main | function main |
matlab/matlab_examples.txt · Last modified: 2021/12/07 19:41 by mithat