Challenge

Project 1 - Data Handling and Interpolation

project 1

function x_dot= x_dotfcn(t,x,k,m);
%xdot fuction
x_dot=zeros(2,1);
x_dot(1)=x(2);
x_dot(2)=(-k/m)*x(1);
end
k=input('enter the value spring consant: ')
m=input('enter the value mass: ');
>> tspan=[0 5];
>> x0=[0 0.5]; %initial condition
>> [t,x]=ode45(@(t,x)x_dotfcn(t,x,k,m),tspan,x0);
>> x_dot(1)=x(2);
>> plot(t,x(:,1),'-o');grid;hold;
>> plot(t,x(:,2),'b-');
legend('x1','x2');

enter the value spring consant: 5

k =

5

enter the value mass: 10
Current plot held
>>

ode 23

function x_dot= x_dotfcn(t,x,k,m);
%xdot fuction
x_dot=zeros(2,1);
x_dot(1)=x(2);
x_dot(2)=(-k/m)*x(1);
end
k=input('enter the value spring consant: ')
m=input('enter the value mass: ');
>> tspan=[0 5];
>> x0=[0 0.5]; %initial condition
>> [t,x]=ode23(@(t,x)x_dotfcn(t,x,k,m),tspan,x0);
>> x_dot(1)=x(2);
>> plot(t,x(:,1),'-o');grid;hold;
>> plot(t,x(:,2),'b-');
legend('x1','x2');

enter the value spring consant: 5

k =

5

enter the value mass: 10
Current plot held
>>

ode43 give more accuracy than ode 23 . value will be more accurate

project 2

y= xlsread('project.xlsx'); %read the xcel
A=y(:,1); %altitude
T=y(:,2); %temperature
p=polyfit(A,T,2); %degree2
q=polyval(p,A);
plot(A,T,'b--');hold;grid;
plot(A,q,'m-');
legend('orginal','using polyfit')

fid= fopen('polyfit_out.txt','w') %write polyfit into text file

for i=1:100

fprintf(fid,'%d/n',polyfit);

end;

fclose(fid);

y= xlsread('project.xlsx');
A=y(:,1);
T=y(:,2);
p=polyfit(A,T,1); %degree1
q=polyval(p,A);
plot(A,T,'b--');hold;grid;
plot(A,q,'m-');
legend('orginal','using polyfit');

degree 3

project 3

function y= fuctionminmax(x); %created the fuction
for i=1:length(x)
y(i)=3*sin((x(i))^2)+cos(x(i))-sin(x(i))*cos(x(i));
end
>> x=[0:pi/100:2*pi];
>> y=fuctionminmax(x);
>> plot(x,y);grid;xlabel('x');ylabel('y');
>> y_min1=fminsearch('fuctionminmax',4) %find min value

y_min1 =

4.1506

y_min2=fminsearch('fuctionminmax',3)

y_min2 =

3.3217

y_max=max('fuctionminmax') %find max value

y_max =

120

>> gtext('min1');gtext('min2');

project 4

contour commend used to generate contour lines by joining points with the same elevation.it represent a 3D surface by plotting the lines that connect points with common z values along a slice.

>> [x,y]= meshgrid(-2:0.2:2.0,-4:0.4:5); %mesh grid fuction to create x and y matrices
>> z=x.*exp(-x.^2-y.^2); %fuction z
>> contour(x,y,z,'showText','on') %show text on display the values along the counter line.

> [x,y]= meshgrid(-2*pi:0.2*pi:2*pi,-4*pi:0.4*pi:5*pi);
>> z=3*sin(x)-4*cos(y);
>> contour(x,y,z,'showtext','on');

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.