×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Functions at the prompt

Functions at the prompt

Functions at the prompt

(OP)
Hi...

I am writing a code for Newton-Raphson Method. I wrote three M-Files:
1)Function m-file

function f = f(x)
f =  input('Enter Your Function Interms of x   ');

2)Derevitive m-file

function df = df(x)
df = input('Enter The Derivitive Of The Above Function Interms of x   ');


3)Script m-file (was done with help of online resources)

a = input('Enter Your Initial Guess   ');
Tolerance = input('Enter The Desired Tolerance   ');
error = 1;        
n = 0;            

while error > tol
   x = a - f(a)/df(a);
   error = abs(x-a);
   n = n+1;
   if n > 25
      error('Excessive iteration and no convergence.');
   end
   a = x;
end


disp('Tolerance (s)')
disp(Tolerance)
disp('Number of iterations')
disp(n)
disp('Root of function')
disp(x)



----------------------------------------------------

The Script File works just fine, especially the part of having the user to enter his/her values. But as you can see for other M-Files, I want also the user to enter his/her function as well. But the method is simply not working.

I want a way in which the user can input the functions manually. Is there such a way?

Thank you guys.


 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources