Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Intersecting functions 2

Status
Not open for further replies.

samwal

Aerospace
Dec 10, 2004
2
Hi everyone,

I need to know how to find the intersection of two functions. They are both quite complex (no polynomials), but only dependent on one variable. So the goal is to find the value of this variable for which the two functions are equal.
It's part of a simulation, so it should be fast and efficient as well.

Does anybody have a suggestion or know where I could find more info?

Sorry if this is a stupid question, I'm only just starting to learn Matlab.

Thanks,
Sam
 
Replies continue below

Recommended for you

If your two functins are f(x) and g(x) then all you need to do is find the roots of (f(x)-g(x))

I don't have matlab on this machine, so i can't tell you how to do that, but you are basically looking for a Newton-Raphson approach.


for an example (the second one down)

Cheers

Greg Locock
 
Thanks a lot!

Fzero seems like the right solution for my problem, however I'm having some trouble getting it to work.
I would like to define my functions in the m-file I need them in. I believe I have to use a function handle for this (@) but this doesn't work for different reasons.

Here's my problem:

a1 = ((-16/gamma)*(q/omega) + (8/3)*mu*theta0 - 2*mu*(lambdac+lambdai))/(1-0.5*mu^2);
CTelement = Clalpha*(sigma/4)*((2/3)*theta0*(1+(3/2)*mu^2) - (lambdac+lambdai));
CTGlauert = 2*lambdai*sqrt(((V/(omega*R))*cos(alphac-a1))^2 + ((V/(omega*R))*sin(alphac-a1)+lambdai)^2);
F = CTelement - CTGlauert;

lambdai0 = 0.05;
lambdai = fzero(F,lambdai0)

lambdai is the variable in functions a1, CTelement and CTGlauert. All other parameters are constants. The goal is to find lambdai for which F becomes zero.

How do I define these functions properly and use the fzero command on them?
The way it is stated here, Matlab doesn't know what to do with lambdai in the functions a1. When I fill everything in into the F function (rather unelegant:)) Matlab doesn't know what the constants are despite that I defined them before in the m-file.

Any help appreciated! Again thanks in advance.

Kind regards,
Sam
 
These equations seem familiar, my guess is that you are iterating on the inflow for a rotor thrust calculation, possibly for a trim condition. I believe you may be posing the problem incorrectly. Typically, the derivate is analytically derived, and newton iteration is used to iterate on inflow coefficient. However, the following code does solve the equations as you posed them.

Good Luck
John

function junk

global gamma q omega mu theta0 lambdac Clalpha sigma V R alphac
gamma = 1.08;
q=24;
omega=600/19;
mu=0.2;
theta0=8*pi/180;
lambdac=0;
Clalpha=5.1;
sigma=(2*19*3)/(pi*19^2);
V=20/600;
R=19;
alphac=0;

lambdai0 = 0.05;
lambdai = fzero(@my_F,lambdai0)

function F=my_F(lambdai)

global gamma q omega mu theta0 lambdac Clalpha sigma V R alphac
a1 = ((-16/gamma)*(q/omega) + (8/3)*mu*theta0 - 2*mu*(lambdac+lambdai))/(1-0.5*mu^2);
CTelement = Clalpha*(sigma/4)*((2/3)*theta0*(1+(3/2)*mu^2) - (lambdac+lambdai));
CTGlauert = 2*lambdai*sqrt(((V/(omega*R))*cos(alphac-a1))^2 + ((V/(omega*R))*sin(alphac-a1)+lambdai)^2);
F = CTelement - CTGlauert;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor