# Untitled

By: a guest on May 8th, 2012  |  syntax: MatLab  |  size: 1.44 KB  |  hits: 18  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. function cosinefunc()
2.
3. %%%%%%%%%%%%%%%%%
4. %created by Hayden Sutherland
5. %16242270
6. %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
7. %%%%%%%%%%%%%%%%%
8.
9. %ask the user for the low end of x's domain
10. xlow=input('what is the lowest x value you wish to use');
11.
12. %ask the user for the upper end of the x domain
13. xhigh=input('what is the largest x value you wish to use');
14.
15. %ask the user to define the constant in front of the x squared
16. Kconst=input('what is the value of the constant in front of the x squared');
17.
18. %the function now uses the users answers to genertaete the x vector
19. x=[xlow:0.01:xhigh];
20.
21. %the function then feeds the x vector into the stand alone function to get a y value vector
22. Yvec=Ysolver(x,Kconst);
23.
24. %the x vector and y vector are now plotted against each other to help wiht the estimation of the roots
25. plot(x,Yvec);
26.
27. % the function prompts the user for their guess for the roots location
28. Xguess=input('what is your estimated guess for x when y=0');
29.
30.
31. % the fzero function is used to caluculate where the roots are using the user estimation
32. @Ysolver=@(x) Ysolver(x, Kconst);
33. Xzero=fzero(@Ysolver,Xguess);
34.
35. % the roots are displayed to the user in a friendly format
36. disp(['Y=0 when x=' num2str(Xzero) ' and x=-' num2str(Xzero)])
37.
38.
39. % the Xzero value is fed into the orginal funcion to test the answer
40. Y=cos(Xzero)-(Xzero)*(Xzero)