1 view (last 30 days)

Show older comments

Hello,

I have a function F = quad(x,REF)

function F = quad(x,REF)

F(1) = x(3)/((T(1)/x(1))-1) + log(x(2)) - log(dv(1))

F(2) = x(3)/((T(2)/x(1))-1) + log(x(2)) - log(dv(2))

F(3) = x(3)/((T(3)/x(1))-1) + log(x(2)) - log(dv(3))

F(4) = x(3)/((T(4)/x(1))-1) + log(x(2)) - log(dv(4))

F(5) = x(3)/((T(5)/x(1))-1) + log(x(2)) - log(dv(5))

F(6) = x(3)/((T(6)/x(1))-1) + log(x(2)) - log(dv(6))

F(7) = x(3)/((T(7)/x(1))-1) + log(x(2)) - log(dv(7))

F(8) = x(3)/((T(8)/x(1))-1) + log(x(2)) - log(dv(8))

end

I'd like to feed different dv and T values from the main program and solve. I've tried the below code from another post (modified and played around a bit to no avail). How can I feed dv and T values into the function quad and then use fsolve?

REF = [x,dv,T];

f =@(x) quad(x,REF);

options = optimoptions('fsolve','Display','iter');

% fun(dv,T) = @quad;

x0 = [150,0.045,7.5];

[out,fval] = fsolve(f,x0,options)

This works fine when the T and dv are already in the function quad, but I don't want to manually copy and paste new values of dv and T in.

function F = quad(x)

dv = [3610.30 2040.80 1203.70 483.04 106.03 15.54 3.39 1.97]

T = [-40 -35 -30 -20 0 40 100 135] + 273.15

F(1) = x(3)/((T(1)/x(1))-1) + log(x(2)) - log(dv(1))

F(2) = x(3)/((T(2)/x(1))-1) + log(x(2)) - log(dv(2))

F(3) = x(3)/((T(3)/x(1))-1) + log(x(2)) - log(dv(3))

F(4) = x(3)/((T(4)/x(1))-1) + log(x(2)) - log(dv(4))

F(5) = x(3)/((T(5)/x(1))-1) + log(x(2)) - log(dv(5))

F(6) = x(3)/((T(6)/x(1))-1) + log(x(2)) - log(dv(6))

F(7) = x(3)/((T(7)/x(1))-1) + log(x(2)) - log(dv(7))

F(8) = x(3)/((T(8)/x(1))-1) + log(x(2)) - log(dv(8))

end

(CALLED FROM THE MAIN AS:)

fun = @quad;

x0 = [150,0.045,7.5];

[out,fval] = fsolve(fun,x0,options)

Stephen Cobeldick
on 3 Apr 2021

dv = [3610.30,2040.80,1203.70,483.04,106.03,15.54,3.39,1.97];

T = [-40,-35,-30,-20,0,40,100,135] + 273.1;

f = @(x) myquad(x,dv,T);

x0 = [150,0.045,7.5];

[out,fval] = fsolve(f,x0)

function F = myquad(x,dv,T)

F(1) = x(3)/((T(1)/x(1))-1) + log(x(2)) - log(dv(1));

F(2) = x(3)/((T(2)/x(1))-1) + log(x(2)) - log(dv(2));

F(3) = x(3)/((T(3)/x(1))-1) + log(x(2)) - log(dv(3));

F(4) = x(3)/((T(4)/x(1))-1) + log(x(2)) - log(dv(4));

F(5) = x(3)/((T(5)/x(1))-1) + log(x(2)) - log(dv(5));

F(6) = x(3)/((T(6)/x(1))-1) + log(x(2)) - log(dv(6));

F(7) = x(3)/((T(7)/x(1))-1) + log(x(2)) - log(dv(7));

F(8) = x(3)/((T(8)/x(1))-1) + log(x(2)) - log(dv(8));

end

Sulaymon Eshkabilov
on 2 Apr 2021

Edited: Sulaymon Eshkabilov
on 2 Apr 2021

Here is a combined and a bit simplified solution:

options = optimoptions('fsolve','Display','iter');

x0 = [150,0.045,7.5];

dv = [3610.30 2040.80 1203.70 483.04 106.03 15.54 3.39 1.97];

T = [-40 -35 -30 -20 0 40 100 135] + 273.15;

[out,fval] = fsolve(@(x)([ x(3)/((T(1)/x(1))-1) + log(x(2)) - log(dv(1));

x(3)/((T(2)/x(1))-1) + log(x(2)) - log(dv(2));

x(3)/((T(3)/x(1))-1) + log(x(2)) - log(dv(3));

x(3)/((T(4)/x(1))-1) + log(x(2)) - log(dv(4));

x(3)/((T(5)/x(1))-1) + log(x(2)) - log(dv(5));

x(3)/((T(6)/x(1))-1) + log(x(2)) - log(dv(6));

x(3)/((T(7)/x(1))-1) + log(x(2)) - log(dv(7));

x(3)/((T(8)/x(1))-1) + log(x(2)) - log(dv(8));]), x0,options)

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

Start Hunting!