I need to find the roots of a function using secant or babylonian method.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I need to find the roots of the attached equation. Ultimately, I am trying to solve for DL. Pb, betaLR, and bR are input from the user, and I have written that code here.
prompt1 = 'Enter value for BLR: ';
BLR=input(prompt1);
prompt2= 'Enter value for bR: ';
bR=input(prompt2);
prompt3 = 'Enter value for desired breakage probability: ';
Pb=input(prompt3);
The next step, I thought, was to write a function to output alphaLR. I wrote it like this as a f1.m
function aLR = f(bR,BLR);
aLR = exp(bR/BLR)*-1;
The output of this function only gives me 'ans' and not an assigned variable 'aLR' for me to use from there on out, so that is my first issue.
My second issue is that I don't know whether to use secant or babylonian method. I am very new to MATLAB and I do not know which one would require fewer iterations, even though I have tried my best to learn what I could about each method. Furthermore, the program requires that the user input a convergence tolerance, and I do not understand how that will affect the number of iterations performed in the program.
Basically, I have tried everything I know how to do and have read every relevant think I could find and I am still completely stuck. I need help!
0 comentarios
Respuestas (1)
Walter Roberson
el 9 de Oct. de 2016
The meaning of
function aLR = f(bR,BLR);
aLR = exp(bR/BLR)*-1;
is that there is one positional output value and two positional input values for a function named f, and that within the function the first positional input value will be called bR and the second positional input value will be called BLR and the one positional output value will be called aLR, and that the action of assigning to the variable aLR will change what is output to the first position. However, this does not in itself affect any variable outside of the function: variables outside the function are only affected if you assign the result of the call to f to the variable.
Consider
function customer = add_donut(customer)
customer = customer + donut;
If you invoke this with
add_donut(kelsey)
then this does not mean that afterwards there is a variable named "customer" containing kelsey-with-donut .
Indeed, when run in that form, it doesn't even mean that afterwards that kelsey would have gained a donut, because what would be passed in and operated on would be a copy of kelsey, a hypothetical kelsey, and the output would be what the hypothetical kelsey-with-donut would be like. It is not until you say "Okay, make the actual kelsey the same as this hypothetical version" that kelsey gets changed:
kelsey = add_donut(kelsey)
2 comentarios
Walter Roberson
el 9 de Oct. de 2016
Your earlier f had 2 input arguments and your new f has 3 input arguments. You might have forgotten to change one of the places that you called upon f.
Alternately if you are trying to pass the function f to another function, then you might have used something like
plot_response(f, x)
but that would mean that f is to be invoked with no arguments and the result of f is to be passed into plot_response . If you are trying to pass a function into a routine to be called by the routine then you need to pass its handle:
plot_response(@f, x)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!