where are the errors in my code? please help me!!
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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)
0 Commenti
Risposta accettata
Torsten
il 25 Mag 2022
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 Commenti
Più risposte (1)
Walter Roberson
il 26 Mag 2022
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.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!