2

Trying to use vpa() to compute a variable point number for a rational expression in an exponent:

syms x;
ans1 = x^(12345/67890)
ans2 = vpa(x^(12345/67890),3)
ans2_5 = vpa((12345/67890),3)
ans3 = vpa(x*(12345/67890),3)

The above shows the issue. ans1 shows the default output of the expression. ans2 shows that vpa() is not computing the variable point number for the expression. ans 2_5 shows what it should be computing to. The result I'm looking for is x^0.182.

ans3 just shows that vpa() produces the expected result when the function is multiplication--it's something in the exponent that's tripping it up.

How can I request that the exponent be evaluated by vpa?

[edit]

Maybe I can make this more clear. All I really need is an accessor or index to the exponent of an exponential expression. So if my expression is y = x^a I need to be able to have some accessor on x that returns a.

Is this possible?

Trevor
  • 181
  • 1
  • 7

1 Answers1

3

+1 for spotting this interesting bug. This solved your problem for me:

digits(3)
p=vpa(12345/67890,3)
ans1 = x^p

ans1 =
       x^0.182
bla
  • 25,846
  • 10
  • 70
  • 101
  • For the example as I presented it your solution works. However for the actual use-case, the whole exponential expression results from solving a system of equations, so I can't pick out just the exponent component to call it a variable (I don't think). Any tricky suggestions there? – Trevor Jan 16 '13 at 03:27
  • I'm afraid VPA is not the tool to use, as I understand now that there is no bug. `vpa(A,d)` computes each element of A to at least d decimal digits of accuracy, where d is the current setting of digits. But if `A=x^d`, there's no way to know about the first `d` digits of `A` hence the outcome. – bla Jan 16 '13 at 03:47
  • Because multiplication (and addition) is separable and power operations are not. When multiplying `x*d`, you can separate the two components, unknown `x` and its scaling factor `d` which is known, hence when writing `vpa(x*d)`, what actually happen is `x*vpa(d)`. However, in the case of `x^d`, vpa cannot tell anything about the accuracy of `x^d` because the power operation is not separable, you cannot write it as c*X, and only if `x` will be some known number, say 3, then `3^d` will be some known number that vpa could operate on. – bla Jan 16 '13 at 18:30
  • Sure, but it could still evaluate the exponent on its own, so that the result would be x^vpa(d). I don't want a single number, I want an expression in terms of x. It's doing the right thing now, it's just giving me a rational number where I want a decimal. – Trevor Jan 16 '13 at 20:34