Given the function
y = xcos(x)
evaluate y for 30 evenly spaced values of x in the
range -140 degrees to 120 degrees. Display this as
a two column table, with the values of x being in the first
column and y in the second.
Save this script in a file named evaluate1.m.
x=linspace(-140,120,30); y = x.*cosd(x); result=[x' y']; disp(result);
| xnew | = | xsin(theta) + y2tan(theta) | |
| ynew | = | x3cos(theta) - ysin(theta) |
Save this file as a script. Test this function by invoking it from matlab.
function [xnew ynew] = transform2(A,theta) x=A(1,:); y=A(2,:); xnew = x.*sind(theta) - (y.^2).*tand(theta); ynew = (x.^3).*cosd(theta) - y.*sind(theta);
A function f(n) is defined as follows:
| f(n) = | { |
|
Save this file as a script. Test this function by invoking it from matlab.
function ans = recurse1(n) if (n == 0) || (n == 1) ans = 1; else ans = recurse1(n-1) + recurse1(n-2); end