NONLINEAR EQUATIONS WITH FSOLVE

Hello people, I would know how to obtain a vector of solution. I have 2 nonlinear function, and I need to obtain for each temperature two variable of solution; So in sum up , I need obtain a matrix with temperatures and 2 solution variables. Thanks!!!

 Accepted Answer

I have no idea what your function is. You can do something like this:

T = linspace(270, 300, 10);                             % Create Temperature Vector
p0 = [1; 1];                                            % Initial Parameter Estimates (Column Vector)
fcn = @(p,T) (p(1)*T.^2 - p(2)*T - 10);                % Create Function With Two Parameters
for k1 = 1:numel(T)
    P(:,k1) = fsolve(@(p)fcn(p,T(k1)), p0);             % Solve & Store Results For Each Value Of ‘T’
end
figure
plot(T, P)
grid

4 Comments

I have tried the syntaxis that you gave me, for fsolve but It didn´t work.
my two nonlinear equation are (both equations equal 0)
1__ (((P^2)*(X(1)-X(2))*(3*X(1)+X(2))^3)/((FCH40-X(1))*(3*FCH40-X(1)-X(2))*(4.01*FCH40+2*X(1))^2))-10.^((-11650./T(:,1))+13.076);
2__ (((0.01*FCH40+X(2))*(3*X(1)+X(2)))/((X(1)-X(2))*(3*FCH40-X(1)-X(2))))-10.^((1910./T(:,1))-1.784)
My variables are are "X(1)" and "X(2)" ; and the scalars are "P=35" and "FCH4=100".
but "T" is a vector array , and the range is from 923 to 1123, where the increment is 10.
After each iteration the matrix that stores my result seams to increased in size.
If you could help me, I would thank you a lot.

I am not certain what you want to do.

This uses ‘T’ as a single vector entirely (rather than for each element):

P     =  35;
FCH40 = 100;
T     = [923 : 10 : 1123]';
X0    = [1; 10];
fcn = @(X) [(((P^2)*(X(1)-X(2)).*(3*X(1)+X(2)).^3)./((FCH40-X(1))*(3*FCH40-X(1)-X(2))*(4.01*FCH40+2*X(1))^2))-10.^((-11650./T(:,1))+13.076); 
            (((0.01*FCH40+X(2))*(3*X(1)+X(2)))./((X(1)-X(2))*(3*FCH40-X(1)-X(2))))-10.^((1910./T(:,1))-1.784)];
XS = fsolve(fcn, X0);

This considers each element of ‘T’ in a loop:

P     =  35;
FCH40 = 100;
T     = [923 : 10 : 1123]';
X0    = [1; 10];
fcni = @(X,Ti) [(((P^2)*(X(1)-X(2)).*(3*X(1)+X(2)).^3)./((FCH40-X(1))*(3*FCH40-X(1)-X(2))*(4.01*FCH40+2*X(1))^2))-10.^((-11650./Ti)+13.076); 
            (((0.01*FCH40+X(2))*(3*X(1)+X(2)))./((X(1)-X(2))*(3*FCH40-X(1)-X(2))))-10.^((1910./Ti)-1.784)];
for k1 = 1 : numel(T)
    XS(:,k1) = fsolve(@(X) fcni(X,T(k1)), X0);
end
figure(1)
plot(T, XS)
grid

The plot makes it easier to see the solutions.

Experiment to get the result you want.

It worked, that was exactly what I needed. Thank you for your time, I really appreciate it!!!
As always, my pleasure!

Sign in to comment.

More Answers (1)

Torsten
Torsten on 20 Apr 2018
Call fsolve in a loop for the different termperatures. Save the solutions of each run in a (2xn) matrix (n = number of temperatures).
Best wishes
Torsten.

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!