
Untitled
By: a guest on
May 8th, 2012 | syntax:
MatLab | size: 1.44 KB | hits: 18 | expires: Never
function cosinefunc()
%%%%%%%%%%%%%%%%%
%created by Hayden Sutherland
%16242270
%the purpose of this function is to find any point on a graph by showing a graph and working off a users estimation of the desired points location
%%%%%%%%%%%%%%%%%
%ask the user for the low end of x's domain
xlow=input('what is the lowest x value you wish to use');
%ask the user for the upper end of the x domain
xhigh=input('what is the largest x value you wish to use');
%ask the user to define the constant in front of the x squared
Kconst=input('what is the value of the constant in front of the x squared');
%the function now uses the users answers to genertaete the x vector
x=[xlow:0.01:xhigh];
%the function then feeds the x vector into the stand alone function to get a y value vector
Yvec=Ysolver(x,Kconst);
%the x vector and y vector are now plotted against each other to help wiht the estimation of the roots
plot(x,Yvec);
% the function prompts the user for their guess for the roots location
Xguess=input('what is your estimated guess for x when y=0');
% the fzero function is used to caluculate where the roots are using the user estimation
@Ysolver=@(x) Ysolver(x, Kconst);
Xzero=fzero(@Ysolver,Xguess);
% the roots are displayed to the user in a friendly format
disp(['Y=0 when x=' num2str(Xzero) ' and x=-' num2str(Xzero)])
% the Xzero value is fed into the orginal funcion to test the answer
Y=cos(Xzero)-(Xzero)*(Xzero)