1

I need to solve a non linear equation involving one variable in variable.
e.g. f(x)=x^1.9+(1-x)*(1-2*x)-1.2545=0

However, there is small complication. The equation also involves one parameter say t and I need to solve the equation for various values of t which I have defined in a vector.

t=0.1:0.1:5.0;
f(x)=t*x^1.9+...+52.25*t=0
solution=[solutions for each value of t]

How do I go about this? I have considered concating a string and then building an inline function out of it and then using fsolve. But I think that's not the best way.

1 Answer 1

1

You can pass parameters into the objective function using anonymous functions.
First define an objective function that takes two arguments x and t

 myFun = @( x, t ) t.*x.^1.9 + ( 1 - x ).*( 1 - 2 * x ) + 52.25*t;

Now you can change t each time:

 ts = 0.1:0.1:5;
 for ti = 1:numel(ts)
     t = ts(ti); % current value for t
     solution(ti) = fsolve( @(x) myFun( x, t ), x0 );
 end
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.