Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Functions at the prompt

Status
Not open for further replies.

AME55

Mechanical
Sep 20, 2005
1
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.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor