how to use solve() without a 'z' variable solution
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alexis
am 23 Jul. 2020
Kommentiert: Alan Stevens
am 24 Jul. 2020
Hi, i'm trying to code a 'hn' and 'hc' solver, it uses those equations and data, but
close all
clear all
clc
%DATA
alfa = degtorad(30);, b = 0.14;, L = b;, m = L*sin(alfa);,k = L*sin(alfa);, pendiente = 0.001;,q = 4;, n = 0.011;
%FUNCTIONS
syms h
d = @(h) b+h.*(m+k);
a = @(h) b.*h+(h.^2)*(m+k)./2;
pm = @(h) b+h.*(sqrt(1+m)+sqrt(1+k));
eta = @(h) h.*(b+h*(m+k)+2*b)./(3*(b+h*(m+k)+b));
fr = @(h) (((q.^2).*d(h))./9.8.*a(h).^3).^0.5;
man = @(h) q.*n./(pendiente.^0.5) == (a(h).^(5/3))./(pm(h).^(2/3));
%SOLUTIONS
rug = eta(h);
hn = solve(man(h),h) %%%%HERE IS MY PROBLEM
hc = solve(fr(h).^2==1,h,) %%%%%HERE IS MY PROBLEM
Ec = hc + (q.^2)/((a(hc).^2)*2*9.8)
En = hn + (q.^2)/((a(hn).^2)*2*9.8)
And when I run it, matlab show me this:
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
> In sym/solve (line 304)
In calculos (line 15)
hn =
5.992149502432489941281916778964
hc =
root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1)
root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 2)
root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 3)
root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 4)
root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 5)
root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 6)
root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 7)
Warning: Solution is not unique because the system is rank-deficient.
> In symengine
In sym/privBinaryOp (line 1030)
In / (line 373)
In calculos (line 17)
Ec =
[ root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1) + 400000/(2401*(root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1)^2 + 2*root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1))^2), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1)]
[ root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 2) + 400000/(2401*(root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1)^2 + 2*root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1))^2), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 2), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 2), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 2), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 2), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 2), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 2)]
[ root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 3) + 400000/(2401*(root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1)^2 + 2*root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1))^2), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 3), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 3), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 3), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 3), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 3), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 3)]
[ root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 4) + 400000/(2401*(root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1)^2 + 2*root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1))^2), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 4), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 4), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 4), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 4), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 4), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 4)]
[ root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 5) + 400000/(2401*(root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1)^2 + 2*root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1))^2), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 5), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 5), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 5), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 5), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 5), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 5)]
[ root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 6) + 400000/(2401*(root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1)^2 + 2*root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1))^2), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 6), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 6), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 6), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 6), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 6), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 6)]
[ root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 7) + 400000/(2401*(root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1)^2 + 2*root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 1))^2), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 7), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 7), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 7), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 7), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 7), root(z^7 + 7*z^6 + 18*z^5 + 20*z^4 + 8*z^3 - 625000/49, z, 7)]
En =
6.0647894215630416283421290892246
>>
so what I want is to get a real number 'hc' without a 'z' variable on them, I think it could be because there are no real solutions but I'm not sure, don't know how to solve that problem, don't even know what it means
0 Kommentare
Akzeptierte Antwort
Alan Stevens
am 24 Jul. 2020
The following gives real results.
%DATA
alfa = deg2rad(30); b = 0.14; L = b; m = L*sin(alfa); k = L*sin(alfa); pendiente = 0.001; q = 4; n = 0.011;
%FUNCTIONS
%syms h
d = @(h) b+h.*(m+k);
a = @(h) b.*h+(h.^2)*(m+k)./2;
pm = @(h) b+h.*(sqrt(1+m)+sqrt(1+k));
eta = @(h) h.*(b+h*(m+k)+2*b)./(3*(b+h*(m+k)+b));
fr = @(h) (((q.^2).*d(h))./9.8.*a(h).^3).^0.5;
fr2 = @(h) (((q.^2).*d(h))./9.8.*a(h).^3) - 1;
man = @(h) q.*n./(pendiente.^0.5) - (a(h).^(5/3))./(pm(h).^(2/3));
%SOLUTIONS
hn = fzero(man, [0 10])
hc = fzero(fr2, [0 10])
rug = eta(hn) % not sure if this is what is wanted for rug
Ec = hc + (q.^2)/((a(hc).^2)*2*9.8)
En = hn + (q.^2)/((a(hn).^2)*2*9.8)
5 Kommentare
Alan Stevens
am 24 Jul. 2020
You are right! But then you only need to change the search range slightly:
%DATA
alfa = deg2rad(30); b = 0.14; L = b; m = L*sin(alfa); k = L*sin(alfa); pendiente = 0.001; q = 4; n = 0.011;
%FUNCTIONS
%syms h
d = @(h) b+h.*(m+k);
a = @(h) b.*h+(h.^2)*(m+k)./2;
pm = @(h) b+h.*(sqrt(1+m)+sqrt(1+k));
eta = @(h) h.*(b+h*(m+k)+2*b)./(3*(b+h*(m+k)+b));
fr = @(h) ((q.^2).*d(h))./(9.8.*a(h).^3).^0.5;
fr2 = @(h) ((q.^2).*d(h))./(9.8.*a(h).^3) - 1;
man = @(h) q.*n./(pendiente.^0.5) - (a(h).^(5/3))./(pm(h).^(2/3));
%SOLUTIONS
hn = fzero(man, [0 10])
hc = fzero(fr2, [1 10])
rug = eta(hn) % not sure if this is what is wanted for rug
Ec = hc + (q.^2)/((a(hc).^2)*2*9.8)
En = hn + (q.^2)/((a(hn).^2)*2*9.8)
Weitere Antworten (1)
Walter Roberson
am 24 Jul. 2020
Bearbeitet: Walter Roberson
am 24 Jul. 2020
R = @(v) sym(v);
%DATA
alfa = R(deg2rad(30));
b = R(0.14);
L = b;
m = L*sin(alfa);
k = L*sin(alfa);
pendiente = R(0.001);
q = R(4);
n = R(0.011);
%FUNCTIONS
syms h
d = b+h.*(m+k);
g = R(9.81);
a = b.*h+(h.^R(2))*(m+k)./R(2);
pm = b+h.*(sqrt(1+m)+sqrt(1+k));
eta = h.*(b+h*(m+k)+R(2)*b)./(R(3)*(b+h*(m+k)+b));
fr = sqrt(((q.^R(2)).*d)./g.*a.^R(3));
man = q.*n./sqrt(pendiente) == (a.^(R(5)/R(3)))./(pm.^(R(2)/R(3)));
%SOLUTIONS
rug = eta;
hn = solve(man,h);
display(hn)
hc = solve(fr.^R(2)==R(1), h);
display(hc)
fprintf('hc has %d total solutions\n', length(hc));
hcr = hc;
hcr(imag(hcr)~=0) = [];
fprintf('hc has %d real-valued solutions\n', length(hcr));
if isempty(hcr)
fprintf('No real solutions for hc. Giving up\n');
else
Ec = hcr + (q.^R(2))/((subs(a,h,hcr).^R(2))*R(2)*g);
display(Ec)
En = hn + (q.^R(2))/((subs(a,h,hn).^R(2))*R(2)*g);
display(En)
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Special Values finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!