Professional Documents
Culture Documents
end
clear all
close all
c=input('Enter a temperature in Celsius : ')
f=(9/5).*c+32;
disp('Temperature in Fahrenheit = ')
disp([f])
clear all
close all
theta=linspace(0,2*pi,100);
for r=0:10
x=r*cos(theta);
y=r*sin(theta);
plot(x,y,'r');
hold on
end
axis('equal');
xlabel('rcos(theta)')
ylabel('rsin(theta)')
title('circle with radius 0-10')
gtext('Circles');
function[y] = Euler(f,e,x0,y0,h,b)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
n=(b-x0)/h;
disp(' i x y(Euler) y(Exact) Error')
for i=0:n
diff=abs(e(x0)-y0);
disp([ i x0 y0 e(x0) diff]);
y=y0+h*f(x0,y0);
x0=x0+h;
y0=y
end
end
function x = Gauss_1(A, b)
% Solve linear system Ax = b
% using Gaussian elimination without pivoting
% A is an n by n matrix
% b is an n by k matrix (k copies of n-vectors)
% x is an n by k matrix (k copies of solution vectors)
[n, n] = size(A); % Find size of matrix A
[n, k] = size(b); % Find size of matrix b
x = zeros(n,k); % Initialize x
for i = 1:n-1
m = -A(i+1:n,i)/A(i,i); % multipliers
A(i+1:n,:) = A(i+1:n,:) + m*A(i,:);
b(i+1:n,:) = b(i+1:n,:) + m*b(i,:);
end;
function [ y1 ] = Lagrangefinal(x,y,xi )
% UNTITLED Summary of this function goes here
% Detailed explanation goes here
n=length(x)-1;
ni=length(xi);
L=ones(n+1,ni);
for k=0:n
for kk=0:k-1
L(kk+1,:)=L(kk+1,:).*(xi-x(k+1))/(x(kk+1)-x(k+1));
end
for kk=(k+1):n
L(kk+1,:)=L(kk+1,:).*(xi-x(k+1))/(x(kk+1)-x(k+1));
end
end
y1=y*L;
disp('the corresponding result is : ')
function [L,A]=LU_factor(A,n)
% LU factorization of an n by n matrix A
% using Gauss elimination without pivoting
% LU_factor.m
% A is factored as A = L*U
% Output:
% L is lower triangular with the main diagonal part = 1s.
% U is upper triangular and is stored in the original mtx A
% and must be zeroed out to get U
% K. Ming Leung, 01/26/03
L=eye(n);
for k=1:n
if (A(k,k) == 0) Error('Pivoting is needed!'); end
L(k+1:n,k)=A(k+1:n,k)/A(k,k);
for j=k+1:n
A(j,:)=A(j,:)-L(j,k)*A(k,:);
end
end
clear all
close all
array=[3 -1 5 2 10 12 1];
maximum=array(1);
minimum=array(1);
for i=1:length(array)
if array(i)>maximum
maximum=array(i);
end
if array(i)<minimum
minimum=array(i);
end
end
disp('Maximum number is = ')
disp([maximum])
disp('Minimum number is = ')
disp([minimum])
function [ a ] = numcheck( p )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
if p>0
disp('the number is positive')
else
disp('the number is negative')
end
end
function [ p ] = prime( n )
% m is initialization
%n is given number
for m=2:floor(sqrt(n))
if mod(n,m)==0
disp('The number is not prime');
p=n;
return
else if mod(n,m)~=0
disp('The number is prime');
p=n;
end
end
end
clear all
close all
a=input('Enter a number : ')
if isprime(a)
disp('The number is prime ')
else
disp('The number is not prime ')
end
ip=1:4;
f_z=0.0;
for ii=1:4
jj=find(ip~=ii);
prod=f(ip(ii));
for kk=jj
prod=prod*(z-x(ip(kk)))/(x(ip(ii))-x(ip(kk)));
end
f_z=f_z+prod;
end
clear all
close all
a=765;
b=str2num(fliplr(num2str(a)))
clear all
close all
theta=linspace(0,10*pi,100);
r=exp(-theta/10);
polar(theta,r)
clear all
close all
sum1=0.0;
n=input('Enter the number limit :')
for i=1:n
sum1=sum1+i;
end
disp('the summation of numbers : ')
disp([sum1])
h=(b-a)/n;
sum1=f(a)+f(b);
sum2=0.0;
for i=1:n-1
sum2=sum2+f(a+i*h);
end
Area=(h/2)*(sum1+2*sum2);
disp(' The required area is :')