Message Boards Message Boards

GROUPS:

Newbie question: How to stop the API from treating variables as integers?

Posted 5 years ago
4628 Views
|
1 Reply
|
0 Total Likes
|

I'm brand new to Wolfram, so apologies in advance if this sounds stupid. I'm trying to use the API to solve an equation involving non-integer numbers, but the documentation is unclear on how to coax the API into recognising the non-integer part. Take this example:

http://www.wolframalpha.com/input/?i=solve+%280.2%5E-a+%3D+2*0.4%5E-a+%2B+1+-+2%29+for+a+not+integer

I'm interested in that numerical solution, ~0.349... The numerical solution is really the only bit I’m interested in but right now I’d settle for the whole XML dump so long as the answer is in there somewhere. I want to be able to get the solution to this from a script inside a Google Sheets document, like this:

function printEquationAnswer(argument) {
  var input = UrlFetchApp.fetch("http://api.wolframalpha.com/v2/query?appid=XXXXX&input="+argument).getContentText();
  return input;
}

... With a cell in the spreadsheet containing something like:

=printEquationAnswer("solve+%280.2%5E-a+%3D+2*0.4%5E-a+%2B+1+-+2%29+for+a+not+integer ")

Which goes to the following URL attempting to solve the equation

http://api.wolframalpha.com/v2/query?appid=XXXXX&input=solve+%280.2%5E-a+%3D+2*0.4%5E-a+%2B+1+-+2%29+for+a+not+integer

But visiting that URL (with a suitable appid in there rather than XXXXX) shows that the result just comes up with a <didyoumean> section rather than an answer. The only way I can get something more like a proper response is to remove the "+not+integer" from the end of the URL... But of course then it performs a "Solution over the integers" and doesn't give me the answer I want. I've tried writing assumptions into the URL but to no avail. I'm presumably getting the syntax wrong, and can't find any documentation with examples of how to do it correctly.

Help! How do I persuade the API to stop treating a as an integer in the same way that you can do so easily on the wolframalpha site itself?

I think a simple way would be to include the domain over which you do want solutions. Instead of ending the query with "+not+integer", try ending with "+rational", "+real", or "+complex":

http://api.wolframalpha.com/v2/query?appid=XXXXX&input=solve+%280.2%5E-a+%3D+2*0.4%5E-a+%2B+1+-+2%29+real

This seems to give the behavior/answer you're looking for.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract