Difference between using "vpasolve" in these 2 codes?

조회 수: 1 (최근 30일)
Eman S
Eman S 2018년 5월 7일
편집: Eman S 2020년 2월 2일
In the following code, I had defined f(x) using syms and to solve this equation, I used vpasolve(f).
syms f(x)
alpha=5;
mio=0.6;
B=2;
if alpha==5
if mio==0.6
if B==2
bast=(x/0.5).^(alpha*(mio-1));
mqam_part1=3*B*((sqrt(3)/2).^(alpha*mio));
mqam_part2=((0.5*sqrt(3)).^(-alpha))+((1.5*sqrt(3)).^(-alpha));
mqam_part3=3*(((x/0.5)).^(alpha*mio));
mqam_part4=((sqrt(3)-(x/0.5)).^-alpha);
mqam_part5=((2*sqrt(3))-(x/0.5)).^-alpha;
mqam_part6=mqam_part4+mqam_part5;
mqam_part7=2*((3-(x/0.5)).^-alpha);
mqam_part8=6*(((x/0.5)).^(alpha*mio));
mqam_part9=6*B*(2.^-alpha);
eqn_LHS=bast/(mqam_part1+mqam_part2)+(mqam_part3*(mqam_part6+mqam_part7));
eqn_RHS=B/((mqam_part8*mqam_part6)+mqam_part9);
f(x)=eqn_LHS-eqn_RHS;
sol_positive = vpasolve(f);
end
end
end
After running this code, it has the following output:
sol_positive =
-0.088528537330827491688440727135052
0.089168332029743739883884412606126
0.33826394036632543530763273039833
1.1599250419465014133554207319948
1.2989629568831597716493684806851
1.6240554937821142318780347702386
4.1380104774956983606108108853334
0.36340277619978535323175586579368 - 0.17885283113851906156582968732142i
1.2992644818621369190151455557302 - 0.31440379416295109163597261773161i
1.4897230890912773483095146949368 - 1.3150774672581101958523122516833i
1.6282605813254473735848321984622 - 0.083684308295293467728903801421506i
1.6955614120462881985070978123707 - 0.34019756525211237400051800951627i
2.8366220103150973884193959600945 - 2.0075730328576518221908039773448i
0.96894287293815413579933338616546 - 1.0029719645739903595813767103315i
2.8366220103150973884193959600945 + 2.0075730328576518221908039773448i
1.2992644818621369190151455557302 + 0.31440379416295109163597261773161i
1.4897230890912773483095146949368 + 1.3150774672581101958523122516833i
0.36340277619978535323175586579368 + 0.17885283113851906156582968732142i
0.96894287293815413579933338616546 + 1.0029719645739903595813767103315i
1.6282605813254473735848321984622 + 0.083684308295293467728903801421506i
1.1475584718883716605696238712257 + 0.23111120566119037717218445710823i
1.6955614120462881985070978123707 + 0.34019756525211237400051800951627i
0.67755561933436425842885030639685 + 0.89740492763981823171766701235696i
0.35356088917929933509194226805741 + 0.46392937489127504001635787211895i
1.1475584718883716605696238712257 - 0.23111120566119037717218445710823i
0.35356088917929933509194226805741 - 0.46392937489127504001635787211895i
0.67755561933436425842885030639685 - 0.89740492763981823171766701235696i
But, in the following code,I had defined the parameters of the equation *B,x,mio using syms and to solve this equation, I used vpasolve(eqn1,x,[0 Inf]).
syms alpha mio B x
alpha=5;
mio=0.6;
B=2;
if alpha==5
if mio==0.6
if B==2
bast=(x/0.5).^(alpha*(mio-1));
mqam_part1=3*B*((sqrt(3)/2).^(alpha*mio));
mqam_part2=((0.5*sqrt(3)).^(-alpha))+((1.5*sqrt(3)).^(-alpha));
mqam_part3=3*(((x/0.5)).^(alpha*mio));
mqam_part4=((sqrt(3)-(x/0.5)).^-alpha);
mqam_part5=((2*sqrt(3))-(x/0.5)).^-alpha;
mqam_part6=mqam_part4+mqam_part5;
mqam_part7=2*((3-(x/0.5)).^-alpha);
mqam_part8=6*(((x/0.5)).^(alpha*mio));
mqam_part9=6*B*(2.^-alpha);
eqn_LHS=bast/(mqam_part1+mqam_part2)+(mqam_part3*(mqam_part6+mqam_part7));
eqn_RHS=B/((mqam_part8*mqam_part6)+mqam_part9);
eqn1=eqn_LHS==eqn_RHS;
sol_positive = vpasolve(eqn1,x,[0 Inf]);
end
end
end
After running this code, it has the following output:
sol_positive =
0.089168332029743739883884412606126
0.33826394036632543530763273039833
1.1599250419465014133554207319948
1.2989629568831597716493684806851
1.6240554937821142318780347702386
4.1380104774956983606108108853334
So, my question is: what is the difference between using vpasolve in the 2 codes and how does it work to give these outputs??
  댓글 수: 2
Image Analyst
Image Analyst 2020년 2월 1일
Original question
What is the difference between using "vpasolve" in the following 2 codes?
In the following code, I had defined f(x) using syms and to solve this equation, I used vpasolve(f).
syms f(x)
alpha=5;
mio=0.6;
B=2;
if alpha==5
if mio==0.6
if B==2
bast=(x/0.5).^(alpha*(mio-1));
mqam_part1=3*B*((sqrt(3)/2).^(alpha*mio));
mqam_part2=((0.5*sqrt(3)).^(-alpha))+((1.5*sqrt(3)).^(-alpha));
mqam_part3=3*(((x/0.5)).^(alpha*mio));
mqam_part4=((sqrt(3)-(x/0.5)).^-alpha);
mqam_part5=((2*sqrt(3))-(x/0.5)).^-alpha;
mqam_part6=mqam_part4+mqam_part5;
mqam_part7=2*((3-(x/0.5)).^-alpha);
mqam_part8=6*(((x/0.5)).^(alpha*mio));
mqam_part9=6*B*(2.^-alpha);
eqn_LHS=bast/(mqam_part1+mqam_part2)+(mqam_part3*(mqam_part6+mqam_part7));
eqn_RHS=B/((mqam_part8*mqam_part6)+mqam_part9);
f(x)=eqn_LHS-eqn_RHS;
sol_positive = vpasolve(f);
end
end
end
After running this code, it has the following output:
sol_positive =
-0.088528537330827491688440727135052
0.089168332029743739883884412606126
0.33826394036632543530763273039833
1.1599250419465014133554207319948
1.2989629568831597716493684806851
1.6240554937821142318780347702386
4.1380104774956983606108108853334
0.36340277619978535323175586579368 - 0.17885283113851906156582968732142i
1.2992644818621369190151455557302 - 0.31440379416295109163597261773161i
1.4897230890912773483095146949368 - 1.3150774672581101958523122516833i
1.6282605813254473735848321984622 - 0.083684308295293467728903801421506i
1.6955614120462881985070978123707 - 0.34019756525211237400051800951627i
2.8366220103150973884193959600945 - 2.0075730328576518221908039773448i
0.96894287293815413579933338616546 - 1.0029719645739903595813767103315i
2.8366220103150973884193959600945 + 2.0075730328576518221908039773448i
1.2992644818621369190151455557302 + 0.31440379416295109163597261773161i
1.4897230890912773483095146949368 + 1.3150774672581101958523122516833i
0.36340277619978535323175586579368 + 0.17885283113851906156582968732142i
0.96894287293815413579933338616546 + 1.0029719645739903595813767103315i
1.6282605813254473735848321984622 + 0.083684308295293467728903801421506i
1.1475584718883716605696238712257 + 0.23111120566119037717218445710823i
1.6955614120462881985070978123707 + 0.34019756525211237400051800951627i
0.67755561933436425842885030639685 + 0.89740492763981823171766701235696i
0.35356088917929933509194226805741 + 0.46392937489127504001635787211895i
1.1475584718883716605696238712257 - 0.23111120566119037717218445710823i
0.35356088917929933509194226805741 - 0.46392937489127504001635787211895i
0.67755561933436425842885030639685 - 0.89740492763981823171766701235696i
But, in the following code,I had defined the parameters of the equation *B,x,mio using syms and to solve this equation, I used vpasolve(eqn1,x,[0 Inf]).
syms alpha mio B x
alpha=5;
mio=0.6;
B=2;
if alpha==5
if mio==0.6
if B==2
bast=(x/0.5).^(alpha*(mio-1));
mqam_part1=3*B*((sqrt(3)/2).^(alpha*mio));
mqam_part2=((0.5*sqrt(3)).^(-alpha))+((1.5*sqrt(3)).^(-alpha));
mqam_part3=3*(((x/0.5)).^(alpha*mio));
mqam_part4=((sqrt(3)-(x/0.5)).^-alpha);
mqam_part5=((2*sqrt(3))-(x/0.5)).^-alpha;
mqam_part6=mqam_part4+mqam_part5;
mqam_part7=2*((3-(x/0.5)).^-alpha);
mqam_part8=6*(((x/0.5)).^(alpha*mio));
mqam_part9=6*B*(2.^-alpha);
eqn_LHS=bast/(mqam_part1+mqam_part2)+(mqam_part3*(mqam_part6+mqam_part7));
eqn_RHS=B/((mqam_part8*mqam_part6)+mqam_part9);
eqn1=eqn_LHS==eqn_RHS;
sol_positive = vpasolve(eqn1,x,[0 Inf]);
end
end
end
After running this code, it has the following output:
sol_positive =
0.089168332029743739883884412606126
0.33826394036632543530763273039833
1.1599250419465014133554207319948
1.2989629568831597716493684806851
1.6240554937821142318780347702386
4.1380104774956983606108108853334
So, my question is: what is the difference between using vpasolve in the 2 codes and how does it work to give these outputs??
Eman S
Eman S 2020년 2월 2일
It will cause confusion to the reader to have comment has the same content of the question. So, please delete this comment. For the original question, It would be the same as it. I only shorten the title of the question.Don't worry, it wouldn't be edited or deleted.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 5월 7일
The fact that you got multiple outputs tells us that the equations define a polynomial. In the case of a polynomial, vpasolve returns all of solutions that meet the defined constraints. In the first case there are no constraints so it returns all of solutions whether real or complex valued. In the second case you included a range, which is equivalent to having added in(x, 0, inf), or (x >= 0 & x <= inf), which acts to eliminate the negative and complex valued solutions.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by