where are the errors in my code? please help me!!

1 回表示 (過去 30 日間)
Abdallah Qaswal
Abdallah Qaswal 2022 年 5 月 25 日
コメント済み: Torsten 2022 年 5 月 26 日
Urgent Help ,please!
I would like to Solve an equation for a variable (y) while setting another variable (r) across a range and then substituting the solution into the upper and lower limits of an integral (q). Eventually, plotting the relationship between the intgeral (q) and the variable (r) with the range.
I know that there are multiple errors! but I can not figure out where are they!!
here is the code:
r=linspace(0,0.09);
syms y(r)
eqn= (cosh(10^10.*y./0.5)).^2 == 5./16.*r;
V1 = double(vpasolve(eqn,[y,r],[0 2]));
V2 = double(vpasolve(eqn,[y,r],[-2 0]));
fun=@(x)0.0018./((5./((cosh(10^10.*x./0.5)).^2)-r.*16).^0.5);
q = integral(fun,V2,V1)
plot(r,q)

採用された回答

Torsten
Torsten 2022 年 5 月 25 日
syms r z
eqn = ((z+1/z)/2)^2 == 5/16*r;
S = solve(eqn,z);
y = log(S)*0.5/10^10
solves the equation
(cosh(10^10.*y./0.5)).^2 == 5./16.*r
for y.
Deduce the conditions on r that V1 and V2 in the subsequent integration are real-valued.
  20 件のコメント
Abdallah Qaswal
Abdallah Qaswal 2022 年 5 月 26 日
Accordingly, the range (0 ,0.09) results in real plotting
Torsten
Torsten 2022 年 5 月 26 日
Yes, the little things ...

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 5 月 26 日
Your first solve() returns multiple roots.
Your vpasolve() is then trying to process all of the roots at the same time .
Remember that solve() and vpasolve() are trying to solve simultaneous equations. If you pass in four equations in one variable, it will not attempt to solve each of the equations independently: it will try to find a single value of the variable that satisfies all of the equations at the same time. (Imagine, for example,that you had a series of trig expressions in a single variable, then you might be trying to find the right period that solves all of the equations at once.)
If you want to solve each equation independently, then use arrayfun() to run solve.
arrayfun(@(Y) vpasolve(Y, r, [0 0.09]), Y, 'uniform', 0)
The 'uniform', 0 is there because vpasolve() might decide there are no solutions.

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by