# Use assume() on find_fit Hi everyone,

does anyone know how I can use assumptions with find_fit? A minimal example would be

var('a,b,x')
assume(a>0,b>0)
find_fit([(2,2),(3,2.9),(4,4.1)],(a+1)/b*x,variables=[x],initial_guess=(-2,-2))


and the output is

[a == -105.66654155674746, b == -104.30685450333799]


Any help or hint on where to find a solution is appriciated. Thanks in advance.

edit retag close merge delete

Considering that find_fit uses Scipy and assumptions are in Maxima, I think it's quite unlikely that this would do much. I guess we could try to run them through assumptions, though this might slow it down appreciably.

Sort by » oldest newest most voted

You could fake it like this:

find_fit([(2,2),(3,2.9),(4,4.1)],(abs(a)+1)/abs(b)*x,variables=[x],initial_guess=(-2,-2))


So the best fit values of a,b are negative, but their absolute values are a "good fit" in your model.

more
{"ft_lang_label":"__label__en","ft_lang_prob":0.9227646,"math_prob":0.9646274,"size":603,"snap":"2023-40-2023-50","text_gpt3_token_len":175,"char_repetition_ratio":0.111853085,"word_repetition_ratio":0.0,"special_character_ratio":0.3416252,"punctuation_ratio":0.18518518,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9982208,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-30T18:51:59Z\",\"WARC-Record-ID\":\"<urn:uuid:2c0edad0-7b0e-4c76-a06a-eaffdaa2adc1>\",\"Content-Length\":\"54009\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e877fa70-37a6-4e09-b38f-687157a0c5ff>\",\"WARC-Concurrent-To\":\"<urn:uuid:bd57815b-3649-47b8-ba7b-c2e0620376fc>\",\"WARC-IP-Address\":\"194.254.163.53\",\"WARC-Target-URI\":\"https://ask.sagemath.org/question/9100/use-assume-on-find_fit/\",\"WARC-Payload-Digest\":\"sha1:4MJPPF2BBG6BP6X7D3O7JLXGTBG2EBDH\",\"WARC-Block-Digest\":\"sha1:J43AUBZ5M5HPC5D5BPDNIISZMZJHY2FX\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510707.90_warc_CC-MAIN-20230930181852-20230930211852-00695.warc.gz\"}"}