spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.21k stars 1.59k forks source link

solving for unconstrained optimization #13829

Closed newbiestudies closed 3 years ago

newbiestudies commented 3 years ago

Description

What steps will reproduce the problem?

I'm trying to learn how to code

import sympy as sym # used for symbolic manipulation of mathematical expressions

x_1 = sym.symbols('x_1') x_2 = sym.symbols('x_2') x_3 = sym.symbols('x_1') x_4 = sym.symbols('x_2') y = sym.symbols('y')

def fd1(x_1,x_2): return (339-.01x_1-.003x_2)x_1 + (399 - .004x_1 - .01x_2)x_2 - (400000+ 195x_1 + 225x_2)

print("The function is defined by fd1(x) =",fd1(x_1,x_2), ".\n") dfdx_1 = sym.diff(fd1(x_1, x_2=x_2),x_1) # take the derivative with respect to x_1

dfdx_1_crpt = sym.solve(dfdx_1, x_1)
print("The derivative is with respect to x_1 is", sym.simplify(dfdx_1), ".\n") print("The critical points are", dfdx_1_crpt,".\n")

f_terms_of_x_1 = dfdx_1_crpt[0] print("Thus x_1 as a function of x_2 is x=", f_terms_of_x_1, ".\n" )

def fd2(x_4,x_3): return (339-.01x_3-.003x_4)x_3 + (399 - .004x_3 - .01x_4)x_4 - (400000+ 195x_3 + 225x_4)

print("The function is defined by fd2(x) =",fd2(x_3,x_4), ".\n") dfdx_2 = sym.diff(fd2(x_4, x_3=x_3),x_4) # take the derivative with respect to x_4

dfdx_2_crpt = sym.solve(dfdx_2, x_4)
print("The derivative is with respect to x_2 is", sym.simplify(dfdx_2), ".\n") print("The critical points are", dfdx_2_crpt,".\n")

f_terms_of_x_2 = dfdx_2_crpt[0] print("Thus x_2 as a function of x_1 is x=", f_terms_of_x_2, ".\n" )

print("The critical points are", dfdx_2_crpt,".\n")

x_1_x_2_sys_crit = sym.solve((dfdx_1,dfdx_2), x_1,x_2)

print("The point(dx_1,dx_2) def by, fd1(dx_1,dx_2), represents the global maximum", x_1_x_2_sys_crit)

print("to interpret",x_1_x_2_sys_crit,"so that it can be used in our code. We put them into a set?\n")

x_1_crit = x_1_x_2_sys_crit[x_1] x_2_crit = x_1_x_2_sys_crit[x_2]

print("these are the values as numbers outside or inside a set?",x_1_crit,x_2_crit)

global_multi_var_sol = sym.solve(fd1(x_1=[x_1],x_2=[x_2]),[x_1],[x_2])

global_multi_var_sol = sym.solve(fd1(x_1=x_1_crit,x_2=x_2_crit),[x_1],[x_2])

print(global_multi_var_sol)

Traceback

  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1392, in handle_hover_response
    self.sig_display_object_info.emit(content,
TypeError: CodeEditor.sig_display_object_info[str, bool].emit(): argument 1 has unexpected type 'list'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Student\anaconda3\lib\logging\__init__.py", line 1081, in emit
    msg = self.format(record)
  File "C:\Users\Student\anaconda3\lib\logging\__init__.py", line 925, in format
    return fmt.format(record)
  File "C:\Users\Student\anaconda3\lib\logging\__init__.py", line 664, in format
    record.message = record.getMessage()
  File "C:\Users\Student\anaconda3\lib\logging\__init__.py", line 369, in getMessage
    msg = msg % self.args
ValueError: incomplete format
Call stack:
  File "C:\Users\Student\anaconda3\Scripts\spyder-script.py", line 10, in <module>
    sys.exit(main())
  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\app\start.py", line 205, in main
    mainwindow.main()
  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3763, in main
    mainwindow = run_spyder(app, options, args)
  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3679, in run_spyder
    app.exec_()
  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\plugins\completion\languageserver\client.py", line 493, in on_msg_received
    self.req_reply[req_id](None, {'params': []})
  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\plugins\completion\languageserver\plugin.py", line 548, in receive_response
    self.sig_response_ready.emit(
  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\plugins\completion\plugin.py", line 123, in receive_response
    self.howto_send_to_codeeditor(req_id)
  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\plugins\completion\plugin.py", line 177, in howto_send_to_codeeditor
    self.skip_and_send_to_codeeditor(req_id)
  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\plugins\completion\plugin.py", line 205, in skip_and_send_to_codeeditor
    self.gather_and_send_to_codeeditor(request_responses)
  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\plugins\completion\plugin.py", line 273, in gather_and_send_to_codeeditor
    response_instance.handle_response(req_type, responses)
  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1019, in handle_response
    handler(params)
  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1406, in handle_hover_response
    self.log_lsp_handle_errors("Error when processing hover")
  File "C:\Users\Student\anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1050, in log_lsp_handle_errors
    logger.error('%', 1, stack_info=True)
Message: '%'
Arguments: (1,)

Versions

Dependencies


# Mandatory:
atomicwrites >=1.2.0           :  1.4.0 (OK)
chardet >=2.0.0                :  3.0.4 (OK)
cloudpickle >=0.5.0            :  1.5.0 (OK)
diff_match_patch >=20181111    :  20200713 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.16.1 (OK)
jedi =0.17.1                   :  0.17.1 (OK)
nbconvert >=4.0                :  5.6.1 (OK)
numpydoc >=0.6.0               :  1.1.0 (OK)
paramiko >=2.4.0               :  2.7.1 (OK)
parso =0.7.0                   :  0.7.0 (OK)
pexpect >=4.4.0                :  4.8.0 (OK)
pickleshare >=0.4              :  0.7.5 (OK)
psutil >=5.3                   :  5.7.0 (OK)
pygments >=2.0                 :  2.6.1 (OK)
pylint >=1.0                   :  2.5.3 (OK)
pyls >=0.34.0;<1.0.0           :  0.34.1 (OK)
qdarkstyle >=2.8               :  2.8.1 (OK)
qtawesome >=0.5.7              :  0.7.2 (OK)
qtconsole >=4.6.0              :  4.7.5 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
rtree >=0.8.3                  :  0.9.4 (OK)
sphinx >=0.6.6                 :  3.1.2 (OK)
spyder_kernels >=1.9.2;<1.10.0 :  1.9.2 (OK)
watchdog                       :  None (OK)
zmq >=17                       :  19.0.1 (OK)

# Optional:
cython >=0.21                  :  0.29.21 (OK)
matplotlib >=2.0.0             :  3.2.2 (OK)
numpy >=1.7                    :  1.18.5 (OK)
pandas >=0.13.1                :  1.0.5 (OK)
scipy >=0.17.0                 :  1.5.0 (OK)
sympy >=0.7.3                  :  1.6.1 (OK)
spyder-bot commented 3 years ago

Thanks for reporting. This issue is a duplicate of #13297. You can solve it now by uninstalling Kite until we properly fix it.