Evaluate parameters in matlab
1 view (last 30 days)
Show older comments
Dear all If I have flow in terms of pressure, resistance1, resistance2 and capacitance, i.e. flow(P,R1,R2,C) and P and flow are arreys. Now given I know what flow and P are, but I need to find values of R1, R2 and C that can produce the given flow when P is an arbitrary arrey. What function can I use to perform the above task in matlab? Many thanks
0 Comments
Accepted Answer
Geoff
on 4 May 2012
Presumably you have a formula that calculates flow, given all the other parameters. I am guessing that you have wrapped this into a function: flow(P,R1,R2,C)
Are R1, R2, and C all scalars/constants?
If so, you can easily use fsolve or fminsearch to calculate them, given your known pressure and flows...
Let's say you have measured flow and pressure in F and P, and a function flow(P,R1,R2,C).
I use fminsearch because it's easy to understand and I don't have the optimization toolbox at the moment =)
Then, parameterise the call to flow (using a vector).
pflow = @(P,x) flow(P, x(1), x(2), x(3));
Now objectify this, by saying you want to minimize the sum of square residuals...
objfn = @(P,F,x) = sum((pflow(P,x) - F) .^ 2);
Make a guess at your initial values for R1, R2 and C:
x0 = [ ?, ?, ? ];
And go:
x = fminsearch( @(x) objfn(P,F,x), x0 );
You don't really have to make objfn (or even pflow) accept P and F... You can just make sure they exist before you define these functions... But if you change them, you'll have to redefine the functions and sometimes it's easy to forget that. Using the way I described, you'll always get a fresh P and F when you execute that fminsearch call.
I think fsolve is much the same... But a little more grunty.
More Answers (0)
See Also
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!