this is my matlab code for class, my professor commented \"why is the eps an input...

70.2K

Verified Solution

Question

Mechanical Engineering

this is my matlab code for class, my professor commented \"why isthe eps an input when it is set inside the function and notspecified as a variable?

how do i fix?

function[] = ()

%Declare Global Variables

global KS;

global KC;

KC = 0;

KS = 0;

End = 0;

while (End == 0)

choice = questdlg('Choose a function', ...

'Fuction Menu', ...

'A','B','B');

switch choice;

case 'A'

Program = 'Start';

while strcmp(Program,'Start');

Choice = menu('Enter the Trigonometric Function you wish tocompute', 'Sin', 'Cos','End');

  

switch Choice;

case 1 %sine

x = input('Input an angle (in Radians):\n'); %x = theta

eps = input('Input a value for epsilon:\n'); %eps=tolerance

[sum] = sine(x,eps);

fprintf('Matlab answer: %5.2f\n',sin(x))

fprintf('Taylor answer: %5.2f\n',sum)

fprintf('KS = %d\n',KS)

fprintf('KC = %d\n',KC)

case 2 %cosine

x = input('Input an angle (in Radians):\n'); %x = theta

eps = input('Input a value for epsilon:\n'); %eps=tolerance

[sum] = cosine(x,eps);

fprintf('Matlab answer: %5.2f\n',cos(x))

fprintf('Taylor answer: %5.2f\n',sum)

fprintf('KS = %d\n',KS)

fprintf('KC = %d\n',KC)

case 3

Program = 'End';

end

end

case 'B'  

% Triangle 1 Given Values

A = 1.0472;

b = 7;

C = 0.5236;

%Finding sides a and c and angle B using Law of Sines

B = pi - (A+C);

c = sine (C) / (sine(B)/b);

a = sine (A) / (sine(B)/b);

  

disp(['Triangle 1'])

fprintf('angle B in radians = %f\n', B);

fprintf('length of side a = %f\n', a);

fprintf('length of side c = %f\n', c);

%Triangle 2 Given Values using Law of Sines and C osines

a = 3;

B = 1.5708;

c = 4;

%Finding side b and angles A and C

b = sqrt((a^2)+(c^2)-(2*a*c*cosine(B)));

C = asin(c * (sine(B)/b));

A = asin(a * (sine(B)/b));

disp(['Triangle 2'])

fprintf('angle of C (in radians) = %f2\n', C);

fprintf('length of side b = %f2\n', b);

fprintf('angle A (in radians) = %f2\n', A);

fprintf('KS = %d\n',KS)

fprintf('KC = %d\n',KC)

end

End = input('Enter 0 to continue or other # to stop: ');

end

%Sine function

function[sum]= sine (x,eps)

KS = KS + 1;

eps = 0.0001;

sum=0;

i=0;

k=1;

while abs(k)>eps

%Taylor Series of Sine

k = (((-1).^i)*((x).^(2*i +1)))/(factorial((2*i)+1));

i = i + 1;

sum= sum+k;

end

end

%Cosine function

function [sum] = cosine (x,eps)

KC =KC + 1;

eps=0.0001;

sum=0;

i=0;

k=1;

  

while abs(k)>eps

%Taylor Series of Cosine

k = (((-1).^i)*((x).^(2*i)))/(factorial((2*i)));

i = i + 1;

sum= sum+k;

end

end

end

Answer & Explanation Solved by verified expert
3.5 Ratings (522 Votes)
eps inputInput a value for epsilonn epstolerance is the input statement in your program After reading the input you are passing eps    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students