dharr

Dr. David Harrington

6501 Reputation

21 Badges

20 years, 44 days
University of Victoria
Professor or university staff
Victoria, British Columbia, Canada

Social Networks and Content at Maplesoft.com

Maple Application Center
I am a retired professor of chemistry at the University of Victoria, BC, Canada. My research areas are electrochemistry and surface science. I have been a user of Maple since about 1990.

MaplePrimes Activity


These are replies submitted by dharr

@Amir Saman Mir Not sure what happened; I get the right answer.

restart

invEqs := [a[3]*cos(theta[1]+theta[2]+theta[3])+a[2]*cos(theta[1]+theta[2])+a[1]*cos(theta[1]) = px, a[3]*sin(theta[1]+theta[2]+theta[3])+a[2]*sin(theta[1]+theta[2])+a[1]*sin(theta[1]) = py, theta[1]+theta[2]+theta[3] = phi]

[a[3]*cos(theta[1]+theta[2]+theta[3])+a[2]*cos(theta[1]+theta[2])+a[1]*cos(theta[1]) = px, a[3]*sin(theta[1]+theta[2]+theta[3])+a[2]*sin(theta[1]+theta[2])+a[1]*sin(theta[1]) = py, theta[1]+theta[2]+theta[3] = phi]

q := [solve(invEqs, {theta[1], theta[2], theta[3]}, explicit)]

Two solutions - try each below - both give the same answer for cos(theta[2])

nops(q)

2

We want cos(theta[2])

c := simplify(eval(cos(theta[2]), q[1]))

(1/2)*(-2*cos(phi)*px*a[3]-2*py*sin(phi)*a[3]+px^2+py^2-a[1]^2-a[2]^2+a[3]^2)/(a[2]*a[1])

In terms of qx and qy

simplify(eval(c, {px = qx+a[3]*cos(phi), py = qy+a[3]*sin(phi)}))

(1/2)*(qx^2+qy^2-a[1]^2-a[2]^2)/(a[2]*a[1])

NULL

 

Download theta.mw

@tarik_mohamadi NullSpace(R1) leads to nonzero entries for only entry 5 and 7, showing that columns 5 and 7 are multiples of each other.

Determinant.mw

@lemelinm Sorry, I don't really understand what you are asking. You wanted Maple to do it automatically, and it does. You must have i<>j to fit a polynomial - if you had two y values for the same x value then it is not a function, and it cannot be a polynomial. If you try the i=j case, with two x values the same, then Maple correctly produces an error.

Interpolation of higher order polynomials will not be unique and they will tend to oscillate, so that is usually not useful.

You can construct your l_i(xi) by, for example

n:=4:i:=3:mul((xi-x[j])/(x[i]-x[j]), j in {$1..n} minus {i})

 

@ogunmiloro If you want values every 0.1 you can just set up a loop:

sim_plot.mw

@MPM2357 This is great - the bug has been fixed in 2021.0. I was using 2017. Note the general solution you got has sin(Pi*n*(r-1))=sin(Pi*n*r), but Maple 2017 got sin(2*Pi*n*r), I should have looked more carefully at your output before I ran the worksheet. So your general solution was the sum over n of sol4 (eq8), so you could start from that point directly. 

@Pepini Even without the IC there is no general solution. I think abs is a problem here. Perhaps there are some manipulations that could be done, like separating into magnitude and phase, but you probably need to know where you are headed.

The line assigning to pe is incomplete - it ends in ^

@J4James So there is no explicit solution for this. So the best you can do is to use unapply to make a function (procedure) out of it, and then use it for numerical work. The plot shows though, that the equation has multiple solutions and it is jumping from one to another, though perhaps it doesn't for the range of H you want.

In principle, you can use evalindets to alter the RootOf's to the form of RootOf which supplies a range to force the right root, but you need to know what its approximate value is. Or probably easier to use fsolve earlier, forcing the right roots by specifying ranges.

eta(H)sheet2.mw

@J4James Hard to diagnose without a worksheet.

@J4James The RootOf suffices for numerical work. If you instead want an analytical solution, you might be able to get one using the "explicit" option in solve. Normally, if you want an analytical (symbolic) solution, you would do the manipulatiions and solving without putting in floating point numerical values, and then put these in at the end.

@AmirHosein Sadeghimanesh  You asked for commands within Maple, and these come the closest to what you asked for. I mentioned them in case you wren't aware of them. So within Maple, I think there are no such features. There may be outside code editors - I don't know much about VSCode. Notepad++ has a Maple plugin, but I haven't used it. There may be others; perhaps others can provide suggestions.

@vv Thanks. As you see, I tried solve but assumed that it worked in the complex domain, as is generally true for Maple. Now I check the help for solve,ineq I see the restriction is stated.

So:

is(p1,nonnoegative) works in the complex domain

solve(p1>=0) works in the real domain (and gives answers that are incorrect in the complex domain)

solve(p1=0) works in the complex domain.

Very confusing, and close to a bug IMO. Perhaps solve(p1>=0) should give a warning.

While I expect that in math, p>0 implies p is real, I don't expect that x^2<0 precludes x=I.

restart;

IsQformNonNeg takes a quadratic form with real coefficients and returns true if it is non-negative for any real values of the variables.

Set infolevel[IsQformNonNeg]:=2 to output the Matrix and its eigenvalues.

IsQformNonNeg:=proc(p::polynom)  # polynomial with names as variables and constants as coefficients
  local i,j,term,p1,terms,nvars,vars,tvars,A,a,tf;
  uses LinearAlgebra;
  p1:=expand(p);
  vars:=[indets(p1,assignable(name))[]];
  nvars:=nops(vars);
  A:=Matrix(nvars,nvars,shape=symmetric);
  if type(p1,`+`) then terms:=[op(p1)] else terms:=[p1] end if; # make list of terms
  for term in terms do
    if degree(term)<>2 then error "not a quadratic form" end if;
    tvars:=indets(term,assignable(name));  # one indet for a*x^2; two for a*x*y
    if nops(tvars)=1 then
      member(tvars[1],vars,'i');
      a:=eval(term,tvars[1]=1);
      if is(Im(a)=0) then
        A[i,i]:=a;
      else
        error "coefficient %1 may have imaginary part",a
      end if;
    else
      member(tvars[1],vars,'i');
      member(tvars[2],vars,'j');
      a:=eval(term,{tvars[1]=1,tvars[2]=1});
      if is(Im(a)=0) then
        A[i,j]:=a/2;
      else
        error "coefficient %1 may have imaginary part",a
      end if;    
    end if;    
  end do;
  if ormap(type,[entries(A,'nolist')],float) then
    WARNING("result may be unreliable for floating point coefficients");
    if Rank(A)<nvars then WARNING("floating point singular matrix increases probability of unreliable result") end if;
  end if;
  userinfo(2,'procname',"Matrix and Eigenvalues:",print(A),Eigenvalues(A,output='list')[]);
  tf:=IsDefinite(A, query = 'positive_semidefinite'); # eigenvalues non-negative
  if not type(tf,truefalse) then error "only true if %1",tf end if;
  tf
end proc:

with(LinearAlgebra):

Two cases that are sums of squares and so explicitly non-negative

p1:=expand((x - y/2)^2 + 3/4*y^2);
p2:=expand((x - y)^2 + (y - z)^2 + (z - x)^2);

x^2-x*y+y^2

2*x^2-2*x*y-2*x*z+2*y^2-2*y*z+2*z^2

IsQformNonNeg(p1);
IsQformNonNeg(p2);

true

true

is(p1>=0) assuming real;
is(p2>=0) assuming real;

FAIL

FAIL

But if the coefficients are floats, then the (semi)positive definiteness cannot be reliably determined - here the Matrix is singular and the zero eigenvalue has a small negative floating value.

infolevel[IsQformNonNeg]:=2:
IsQformNonNeg(evalf(p2));
infolevel[IsQformNonNeg]:=0:

Warning, result may be unreliable for floating point coefficients

Warning, floating point singular matrix increases probability of unreliable result

IsQformNonNeg: Matrix and Eigenvalues:

Matrix([[2., -1.000000000, -1.000000000], [-1.000000000, 2., -1.000000000], [-1.000000000, -1.000000000, 2.]])

HFloat(-1.1102230246251565e-16) HFloat(3.0) HFloat(3.0)

false

Error testing

IsQformNonNeg(2);

Error, (in IsQformNonNeg) not a quadratic form

IsQformNonNeg(RootOf(z^2+1)*x^2);

Error, (in IsQformNonNeg) coefficient RootOf(_Z^2+1) may have imaginary part

IsQformNonNeg(Pi*x^2);

true

IsQformNonNeg(arcsin(2)*x^2);

Error, (in IsQformNonNeg) coefficient arcsin(2) may have imaginary part

evalf(arcsin(2));

1.570796327-1.316957897*I

IsQformNonNeg(RootOf(z^2-1)*x^2);

Error, (in IsQformNonNeg) only true if 0 <= RootOf(_Z^2-1)

 

 

Download QformProcedure.mw

@Maple_lover1 From a statistics point of view, the maximum likelihood for normally-distrbuted errors leads to least squares minimization. From a calculation point of view, minimizing least squares is easy because the equations you solve (the normal equations) are linear. I seem to recall that a truncated Fourier series has a minimum least squares error. But without these rationales, and perhaps for your application, you can choose whatever you like.

@acer Agreed, but I have no idea what the OP really wants to do. The point of my post was that you could do something without learning MathML, and that leads to the above procedure. As usual, one can get a better result with some more work, but as an educator, I expect the OP to do some optimization, based on their specific requiremenents. My view of MathML is as for postscript, it is something that you could program, but really it is something for a computer to produce. 

First 43 44 45 46 47 48 49 Last Page 45 of 67