Commit 04feffe6 authored by SHRADDHEYA SHENDRE's avatar SHRADDHEYA SHENDRE

Adding refraction.m (from lab01)

parents
fileID = fopen('input_inlab_task_A1.txt','r'); % Opening input file
formatSpec = '%f'; % format for dealing with floating point numbers, precision is better than 10^(-4)
A = fscanf(fileID,formatSpec); % Taking input from file and storing it in a Column Matrix/Array A
nx = A(1); % Indices start from 1 and not 0
ny = A(2);
fun = @(x) (nx*cos(x)*sin(x/3) + ny*sin(x)*sin(x/3) - sin(x)) ; % Storing the Equation to Solve in fun
x0 = 1.6; % slightly larger than pi/2 -- > Initial Guess, Loose PreCondition : At least one root lies in (0, pi/2)
z = fsolve (fun, x0); % Using fsolve to compute the root and storing it in variable z
file_id = fopen('output_inlab_task_01.txt', 'w'); % opening output File
fprintf(file_id,formatSpec,z); % "Loading" the value of z in Output File
fclose(file_id); % Closing output File -- > Important, without this code doesnt work
% First We tried : z = fzero(fun,x0)
\ No newline at end of file
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