how can i get value of y

2 views (last 30 days)
shaqran alkhraan
shaqran alkhraan on 23 Nov 2021
Edited: John D'Errico on 23 Nov 2021
i write this eqution in matlab and i want find y with varible r
function expansion (r)
h=0.282;
l=0.9;
r1=43.7;
log(r/r1)=((y/h*l)+(2*(log(2-h*l*y+2*h*l^2))/(h^2*l^2))+(-2*(log(2+2*h*l^2))/(h^2*l^2)))

Answers (2)

Jon
Jon on 23 Nov 2021
Edited: Jon on 23 Nov 2021
It looks like you are trying to solve for the root of a nonlinear function. You can use MATLAB's fzero to do this. Type doc fzero on the command line to read the documentation. Please see if this will work for you. If you are still stuck please post what you have tried and what specific problems you are having.
Note you will have to rearrange your expression into the form 0 = f(y,r) assuming you are looking for the value of y that solves this for a fixed value of r then you can set the value of r using an approach illustrated in the documentation under "Root of Function with Extra Parameter".

John D'Errico
John D'Errico on 23 Nov 2021
Edited: John D'Errico on 23 Nov 2021
You want to solve for y, as an implicit function of r?
First, you should consider if a solution exists at all. Is it multi-valued? A good tool to determine things like this is to just plot the relation. As you can see below, I subtracted off the left hand side, so now we are interested in a combination of parameters that make it zero.
h=0.282;
l=0.9;
r1=43.7;
ryfun = @(r,y) -log(r/r1) + ((y/h*l)+(2*(log(2-h*l*y+2*h*l^2))/(h^2*l^2))+(-2*(log(2+2*h*l^2))/(h^2*l^2)))
ryfun = function_handle with value:
@(r,y)-log(r/r1)+((y/h*l)+(2*(log(2-h*l*y+2*h*l^2))/(h^2*l^2))+(-2*(log(2+2*h*l^2))/(h^2*l^2)))
So here we have an implicit function of r and y. fimplicit is designed to plot such a relation.
fimplicit(ryfun)
xlabel r
ylabel y
grid on
So for at least SOME values of r, there are at least two solutions. There may be more solutions. Perhaps what you care about are the positive solutions. They always seem more in demand. And nothing seems to be happening for negative r. That makes sense, since if r< 0, then we will have problems with that log where it will become complex valued. So I'll expand things a bit to focus on positive r and y.
fimplicit(ryfun,[0 10 0 100])
xlabel r
ylabel y
grid on
fimplicit does not seem to find much more. I'll assume it did its best, though I could always be wrong.
WIll an analytical solution exist? Probably not, but there may be one that employs the Lambert W function - a special function that most people never seem to trip over. Regardless, it is trivial to use fzero.
I don't really know what your function expansion is doing, since it returns no arguments. But if we know the value of r, then can we solve for y numerically? That is what fzero does. For example, we have what I called ryfun, an implicit function of those two variables.
ryfun = @(r,y) -log(r/r1) + ((y/h*l)+(2*(log(2-h*l*y+2*h*l^2))/(h^2*l^2))+(-2*(log(2+2*h*l^2))/(h^2*l^2)))
ryfun = function_handle with value:
@(r,y)-log(r/r1)+((y/h*l)+(2*(log(2-h*l*y+2*h*l^2))/(h^2*l^2))+(-2*(log(2+2*h*l^2))/(h^2*l^2)))
rval = 3;
yval = fzero(@(y) ryfun(rval,y),1)
yval = 3.4539
In the call to fzero, I turned ryfun into a simple function ONLY of y that fzero can work on, by effectively substituting a value for r.
And we see that ryfun(rval,yval) will be effectively zero, to within the extent floating point arithmetic can make it so.
ryfun(rval,yval)
ans = -2.6645e-15

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!