An actual non-answer from solve

14 Ansichten (letzte 30 Tage)
Susan
Susan am 2 Jun. 2011
The following code results in a an empty sym. Would anyone care to comment on (a) why no solution? and (b) how to actually get a solution from the symbolic math toolbox?
reset(symengine);clear all;
syms x lambda A k positive;
syms eta;
lambda = sym(1);
k = sym(2*pi);
eq1 = A*sin(eta)-10;
eq2 = A*sin(k*lambda/6 + eta)-20;
eq3 = A*sin(k*5*lambda/12 + eta);
% try to solve
b=solve(eq1,eq2,eq3,A,eta,k)
% --> answer is [ empty sym ]
subs(eq1,{A,eta,k},{20,pi/6,2*pi/lambda})
subs(eq2,{A,eta,k},{20,pi/6,2*pi/lambda})
subs(eq3,{A,eta,k},{20,pi/6,2*pi/lambda})

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 2 Jun. 2011
You force k to equal 2*pi; how do you expect it to solve for any other value?

Weitere Antworten (2)

Walter Roberson
Walter Roberson am 2 Jun. 2011
solve() is failing because you are attempting to solve for k, but k has a value already so eq1 eq2 and eq3 do not contain k anymore. Even if they did somehow still contain k, because k has a value, it would be the value that would be passed in to solve() where you list k at the end; you would need to quote k to get just the name passed in
solve(eq1,eq2,eq3,A,eta,'k')
but like I said this would fail because there is no k in eq* because eq* were constructed after k was defined.

Susan
Susan am 2 Jun. 2011
Ok,I actually didn't mean to ask it to solve for k any more.
Now the following produces the right answer:
b=solve(eq1,eq2,eq3,A,eta)
>> b.A
ans =
20
>> b.eta
ans =
pi/6
Still, I'm wondering what it would take to solve for all three, which was my original quest:
reset(symengine);clear all;
syms x lambda A k positive;
syms eta;
eq1 = A*sin(eta)-10;
eq2 = A*sin(k*lambda/6 + eta)-20;
eq3 = A*sin(k*5*lambda/12 + eta);
% try to solve
b=solve(eq1,eq2,eq3,A,eta,k)b =
[ empty sym ]
  1 Kommentar
Walter Roberson
Walter Roberson am 2 Jun. 2011
Works for me in Maple:
solve([eq1, eq2, eq3], [A, eta, k],UseAssumptions);
[[A = 20, eta = (1/6)*Pi, k = 2*Pi/lambda],
[A = 20, eta = (5/6)*Pi, k = 10*Pi/lambda],
[A = 20, eta = (5/6)*Pi, k = -2*Pi/lambda],
[A = 20, eta = (1/6)*Pi, k = -10*Pi/lambda],
[A = (80/7)*14^(1/2), eta = arctan((1/22)*14^(1/2)*2^(1/2)), k = 12*arctan((1/2)*14^(1/2)*2^(1/2))/lambda],
[A = (80/7)*14^(1/2), eta = -arctan((1/22)*14^(1/2)*2^(1/2))+Pi, k = 12*(-arctan((1/2)*14^(1/2)*2^(1/2))+Pi)/lambda],
[A = (80/7)*14^(1/2), eta = -arctan((1/22)*14^(1/2)*2^(1/2))+Pi, k = -12*arctan((1/2)*14^(1/2)*2^(1/2))/lambda],
[A = (80/7)*14^(1/2), eta = arctan((1/22)*14^(1/2)*2^(1/2)), k = 12*(arctan((1/2)*14^(1/2)*2^(1/2))-Pi)/lambda]]
You have to eliminate the ones with negative k from this, as Maple does not seem to fully process the assumptions on k with the assumptions on lambda,

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by