دستور switch case, if, elseif

clear all

clc

a=10

b=4

% a=1 b=2 c=3

type=input('type','s')

x=input ('x=')


switch lower(type)

    case ('1')

        if x>2

            f=x^2+2*x

        elseif x<2

            f=x^2

        else x=2

            f=40

        end

    case '2'

        if x>8

            f=a+b

        elseif x<8

            f=a*x^2

        else f=100

        end

end

polyval and polyfit ...

clear all

clc

x=[1 2 3 4]

y=[5 6 7 8]

p=polyfit(x,y,2)

y2=polyval(p,x)

e=abs(y-y2)

plot(x,y,'r*')

hold on

plot(x,e,'b')

hold on

plot(x,y2,'g')


دستور رسم بیضی در متلب

clear all
clc
a=input('a=')
b=input('b=')
n=input('n=')
i=1
for x=-a:a/n:a
    y=sqrt(b^2-(x*b/a)^2)
    y1(i)=y
    y2(i)=-y
    x1(i)=x
    i=i+1
end
plot(x1,y1)
hold on
plot(x1,y2)
    

POLAR

clear all

clc

% x=input('x=')

a=input('a=')

% b=input('b=')

r=ones(1,120)*a

teta=0:pi/119:pi

polar(teta,r)

hold on

a=10

r=ones(1,120)*a

teta=-pi:pi/119:0

polar(teta,r)


یا می توانیم به صورت زیر بنویسیم


clear all

clc

% x=input('x=')

a=input('a=')

% b=input('b=')

r=ones(1,120)*a

teta=0:2*pi/119:2*pi

polar(teta,r)

انتگرال با دستور int

clear all
clc
syms x
int(x^2,'5','20')