Commit 3745d709 authored by MOHIT P PATIL's avatar MOHIT P PATIL

Add lab01

parent c3979f30
s=load("input_outlab_task_A1.txt"); %loading the input values
x1=s(1); %assigning the loaded values
y1=s(2);
d=s(3);
w=s(4);
n=s(5);
f=@(x) w*(1-(cos(x)/sqrt((n*n)-(sin(x)*sin(x)))))+(x1*cot(x))-y1; %function made after doing the calculation
l=fsolve(f,0.1); %returns in radians
m=(l*180.0)/pi; %changes to degrees
csvwrite("output_outlab_task_A1.txt",m); %output is printed in this file
76.63 27 0.027 0.0555 7 5 3.5 5
\ No newline at end of file
s=load("input_outlab_task_A2.txt"); %loading the input values
x1=s(1);y1=s(2);v2=s(3);vl=s(4);d=s(5);w=s(6);n=s(7);t1=s(8); %assigning the values
%f=@(x) ((cot(x)*cos(x)*vl)-v2)*(y1-w+((w*n*n*cos(x))/sqrt((n*n)-sin(x)*sin(x))))-(((cos(x)*vl)-v2)*((cot(x)*(y1-d-w))+((w*cos(x)*cos(x)*n)/sqrt((n*n)-(sin(x)*sin(x))))+d));
%t=((((v2*t1)+y1-w)/(cos(x)*vl))+((w*n*n)/sqrt((n*n)-(sin(x)*sin(x)))*vl))/(1-(v2/(cos(x)*vl)));
f=@(x) ((tan(x)*(y1-d-w))+(w*(sin(x)/sqrt((n*n)-(sin(x)*sin(x)))))+(tan(x)*(d+(v2*(((((v2*t1)+y1-w)/(cos(x)*vl))+((w*n*n)/sqrt((n*n)-(sin(x)*sin(x)))*vl))/(1-(v2/(cos(x)*vl)))+t1))))-x1); %function made after doing the calculation
l=fsolve(f,0.1); %returns in radians
t=((((v2*t1)+y1-w)/(cos(l)*vl))+((w*n*n)/sqrt((n*n)-(sin(l)*sin(l)))*vl))/(1-(v2/(cos(l)*vl))); %calculates total time taken to hit the shields
m=(l*180.0)/pi; %returns in degrees
g=x1; %assigning g
y=y1+(v2*(t+t1)); %returns the final y coordinate of the X1 plane
a = [m g y];
csvwrite("output_outlab_task_A2.txt",a); %prints the output in the given file
45.82938637911659,76.63,78.42597391448263
function puzzle=backward_solve_3(s); %function defined
c=ones(3:3); %initial guess
a=[1,1,0,1,0,0,0,0,0; % 9*9 matrix
1,1,1,0,1,0,0,0,0;
0,1,1,0,0,1,0,0,0;
1,0,0,1,1,0,1,0,0;
0,1,0,1,1,1,0,1,0;
0,0,1,0,1,1,0,0,1;
0,0,0,1,0,0,1,1,0;
0,0,0,0,1,0,1,1,1;
0,0,0,0,0,1,0,1,1];
b=s(:); % b column matrix made to be made to add with Ax
m=det(a); %modulus of a
l=mod((m*(a\b)),2);
t=[l(1),l(4),l(7);l(2),l(5),l(8);l(3),l(6),l(9)] % resulting matrix
endfunction
\ No newline at end of file
function f=backward_solve(s); %defining function to solve matrix for solving lights out problem
m=rows(s); %assigns number of rows to m
n=columns(s); %assigns number of columns to n
a=zeros(m*n,m*n); %makes a zero matrix of size mn x mn
for c=1:m;
for d=1:n;
i=c; j=d;
for i= max(i-1,1):min(i+1,m); %used min and max to take care of boundary conditions
a(j+((i-1)*n),((c-1)*n)+d)=1; %assigns the given element of 'a' to 1
endfor
i=c; j=d;
for j= max(j-1,1):min(j+1,n); %used min and max to take care of boundary conditions
a(j+((i-1)*n),((c-1)*n)+d)=1;
endfor
endfor
endfor
p=s'; %assigning adjoint of s to p
b=p(:) ; % b column matrix made to be made to add with Ax
w=det(a); %modulus of a
l=mod((w*(a\b)),2);
% r=@(y) mod((a*y +b),2) ;
% c=ones(m*n,1);
% l=fsolve(r,c)
v=round(l); %rounding off the decimals to integers
mod(v,2);
r=zeros(m,n);
for j=1:m*n
r(j)=v(j);
endfor
mod(r',2)
endfunction
I pledge on my honour that i have not given or received any unauthorised assistance on this assignment or any previous task.
We learnt algorithms for the lights out problem,efficient use of fsolve and other functions of octave very much similar to matlab.Coding for long hours without any breaks.
Fenil: 100%
Rajat:100%
Mohit:100%
Mohit patil(150050017),fenil vanvi(150050003),rajat kapoor(150050037)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment