Insert symbolic equation in another symbolic equation

Hello i have the equation eq5 that has been solved and is now only a function of y. I want now to insert this function (r) inside eq6 and solve that, but it gives me an error. How can i solve this?
eq5 = hw2*(q-r)==y;
r = solve(eq5,r);
eq6 = @(y) sigma*eps*((r^4)-T_inf^4)-y;
y0=0;
sol = fsolve(eq6,y0);

8 Comments

Show us the full code.
this is the full code, i had to solve a 6 equation system (i have substitute the q used before with s in the cose)
Pr_g = (Cp_g*mu_g)/k_g;
hg = 0.023 * (k_g/((D(len-i+1))^1.8)) * (((4*m_dot_g)/(pi*mu_g))^0.8) * (Pr_g^0.33);
hw1 = kw1/tw1;
hw2 = kw2/tw2;
syms x y z p s r
eq1 = hg*(Tc-x)==y;
x = solve(eq1,x);
eq2 = hw1*(x-z)==y;
z = solve(eq2,z);
eq3 = p*(z-Tl)==y;
p = solve(eq3,p);
eq4 = p*(Tl-s)==y;
s = solve(eq4,s);
eq5 = hw2*(s-r)==y;
r = solve(eq5,r);
eq6 = @(y) sigma*eps*((r^4)-T_inf^4)-y;
y0=0;
q = fsolve(eq6,y0);
Your code is still incomplete, you need to give the values for variables.
Pr_g = (Cp_g*mu_g)/k_g;
Unrecognized function or variable 'Cp_g'.
hg = 0.023 * (k_g/((D(len-i+1))^1.8)) * (((4*m_dot_g)/(pi*mu_g))^0.8) * (Pr_g^0.33);
hw1 = kw1/tw1;
hw2 = kw2/tw2;
syms x y z p s r
eq1 = hg*(Tc-x)==y;
x = solve(eq1,x);
eq2 = hw1*(x-z)==y;
z = solve(eq2,z);
eq3 = p*(z-Tl)==y;
p = solve(eq3,p);
eq4 = p*(Tl-s)==y;
s = solve(eq4,s);
eq5 = hw2*(s-r)==y;
r = solve(eq5,r)
eq6 = @(y) sigma*eps*((r^4)-T_inf^4)-y
y0=0;
q = fsolve(eq6,y0);
there are files inside, i should share all the folder, just try to understand what i am doing, numbers are not necessary
i have a function r, which depend on y
i have another function where i want to insert r, so that the equation depends only on y, and solve this last equation to find y
Why not define eq6 as a symbolic expression like you have done for other eq and use solve?
if i use this:
% eq6 = sigma*eps*((r^4)-T_inf^4)==y;
% sol = solve(eq6,y)
it gives me a vector of 4 same elements:
root(z^4 - (148549786974450477987*z^3)/27487790694400 + (66201117630463850684060566839278314716507*z^2)/6044629098073145873530880000 - (25694677813792110401306682574502596589303194435085805665710978025618652510443*z)/2420199345095688424498763567867944239211734959652864000000 + 3804255296569717375581777916032849021112749976946199317897911767146631227587687/1141798154164767904846628775559596109106197299200000000, z, 1)
root(z^4 - (148549786974450477987*z^3)/27487790694400 + (66201117630463850684060566839278314716507*z^2)/6044629098073145873530880000 - (25694677813792110401306682574502596589303194435085805665710978025618652510443*z)/2420199345095688424498763567867944239211734959652864000000 + 3804255296569717375581777916032849021112749976946199317897911767146631227587687/1141798154164767904846628775559596109106197299200000000, z, 2)
root(z^4 - (148549786974450477987*z^3)/27487790694400 + (66201117630463850684060566839278314716507*z^2)/6044629098073145873530880000 - (25694677813792110401306682574502596589303194435085805665710978025618652510443*z)/2420199345095688424498763567867944239211734959652864000000 + 3804255296569717375581777916032849021112749976946199317897911767146631227587687/1141798154164767904846628775559596109106197299200000000, z, 3)
root(z^4 - (148549786974450477987*z^3)/27487790694400 + (66201117630463850684060566839278314716507*z^2)/6044629098073145873530880000 - (25694677813792110401306682574502596589303194435085805665710978025618652510443*z)/2420199345095688424498763567867944239211734959652864000000 + 3804255296569717375581777916032849021112749976946199317897911767146631227587687/1141798154164767904846628775559596109106197299200000000, z, 4)
if i view the entire function r, copy what it is written and substitute it inside works fine, but as it is in the cycle i can't copy and paste manually at every passage

Sign in to comment.

 Accepted Answer

Use vpa to get numerical values. Convert them to double() if you need the values to be in numeric data type.
syms z
%first root, copied from above
sol1=vpa(root(z^4 - (148549786974450477987*z^3)/27487790694400 + (66201117630463850684060566839278314716507*z^2)/6044629098073145873530880000 - (25694677813792110401306682574502596589303194435085805665710978025618652510443*z)/2420199345095688424498763567867944239211734959652864000000 + 3804255296569717375581777916032849021112749976946199317897911767146631227587687/1141798154164767904846628775559596109106197299200000000, z, 1))
sol1 = 
549277.87721495737433337758873113
double(sol1)
ans = 5.4928e+05

3 Comments

thanks! but if i solve every solution that i have, i get different values, why? they are all the same
They look same because the syntax of the output above is same except for the number of root.
Since solve() was unable to find the explicit value, it returns the solution as -
root(equation,variable,1)
root(equation,variable,2)
root(equation,variable,3)
root(equation,variable,4)
You can see at the end of the each expression there's a number, denoting which root it refers to. The value of roots will, of course, depend upon the coefficients.s
thanks for explaining me!

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!