Unknown variable within an equation

조회 수: 2 (최근 30일)
Shozeal
Shozeal 2018년 10월 3일
댓글: Shozeal 2018년 10월 5일
Hello,
I have an equation of the form P*dawson(sqrt(log(P)-log(A)))== sqrt(B)*T to be solved.
Variable A and B are scalar, but variable T is a vector. I need to solve for P in the equation.
This is the code I have written
syms P
T=5:5:500;
A=2;
B=0.5;
eqn = P*dawson(sqrt(log(P)-log(A)))== sqrt(B).*T ;
s = solve(eqn,P)
s =
Empty sym: 0-by-1
That is the solution for s I got.
Please advise what can be done.
Thanks.

채택된 답변

Star Strider
Star Strider 2018년 10월 4일
Try this:
syms P T
A=2;
B=0.5;
eqn = P*dawson(sqrt(log(P)-log(A))) - sqrt(B).*T ; % Rearrange
eqnfcn = matlabFunction(eqn, 'Vars',{P,T}) % Anonymous Function
T=5:5:500;
for k1 = 1:numel(T)
Pv(k1) = fsolve(@(P)eqnfcn(P,T(k1)), 10);
end
figure
plot(T, Pv)
grid
xlabel('T')
ylabel('P')

추가 답변 (2개)

Image Analyst
Image Analyst 2018년 10월 3일
dawson needs to be defined also.
  댓글 수: 2
Image Analyst
Image Analyst 2018년 10월 4일
편집: Image Analyst 2018년 10월 4일
Olufemi's "Answer" moved here:
@Image analyst, sorry I don't get what you mean by Dawson needs to be defined. Dawson is a function in MATLAB. For example, you can have dawson(2) = 3.013403889237920e-01 when solved.
Thank you for the response.
Image Analyst
Image Analyst 2018년 10월 4일
OK, it wasn't in my help. It must be in a toolbox that you have that I don't have.

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


Walter Roberson
Walter Roberson 2018년 10월 4일
syms P
T=5:5:500;
A=2;
B=0.5;
s = arrayfun( @(t) vpasolve(P*dawson(sqrt(log(P)-log(sym(A))))== sqrt(sym(B)).*t, P), T);
plot(T, s)
You have to loop solving one value at a time. With the code you had, you were trying to find a single value for P that satisfied all of the equations at the same time.
  댓글 수: 3
Walter Roberson
Walter Roberson 2018년 10월 4일
You should not have changed the t to T on the line.
You appear to be using R2015a or earlier (I think it was... I would need to check), as a few releases ago arrayfun() started being able to handle sym variables.
syms P
T=5:5:500;
A=2;
B=0.5;
scell = arrayfun( @(t) vpasolve(P*dawson(sqrt(log(P)-log(sym(A))))== sqrt(sym(B)).*t, P), T, 'uniform', 0);
s = double([scell{:}]);
plot(T, s)
Nearly a straight line.
Shozeal
Shozeal 2018년 10월 5일
Hi Walter, I actually use R2017a. So, after keeping the t and T in the expression as written above, I got something close to a straight line too. Though it takes a very long time to run if I should increase the range of T.
Thanks.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by