用Python中的约束求解线性方程

时间:2016-11-14 06:30:33

标签: python linear-equation

我有一个带有一些约束的线性方程组。如果有人能帮助我在Python中解决这个方程组,我将不胜感激。

System of linear equations with some constraints

1 个答案:

答案 0 :(得分:0)

用sympy:http://docs.sympy.org/dev/modules/solvers/solveset.html#sympy.solvers.solveset.linsolve

来解决这个问题应该相当容易

将所有方程式添加到列表中。然后将该列表传递给public class DialogMediaDetails extends DialogFragment { private GoogleMap mGoogleMap = null; private MapView mMapView = null; @Override public final Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dlg = ...; // create dialog View view = ...; // get view from dialog Location location = ...; // defined location initGoogleMap(); return dlg; } private void initGoogleMap(Location location) { mMapView = new MapView(getActivity()); MapsInitializer.initialize(getActivity()); // Updates the location and zoom of the MapView mMapView.onCreate(null); mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(GoogleMap googleMap) { LatLng coordinates = new LatLng(location.getLatitude(), location.getLongitude()); googleMap.addMarker(new MarkerOptions().position(coordinates)); googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 15)); mGoogleMap = googleMap; mMapView.onResume(); } }); mMapView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mMapView.getViewTreeObserver().removeOnGlobalLayoutListener(this); // MapView is scrollable, so we disable dragging CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior(); behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() { @Override public boolean canDrag(AppBarLayout appBarLayout) { return false; } }); } }); replaceHeader(mMapView); } private void replaceHeader(View view) { ViewGroup parent = (ViewGroup) pbHeader.getParent(); int index = parent.indexOfChild(pbHeader); ViewGroup.LayoutParams lp = pbHeader.getLayoutParams(); parent.removeView(pbHeader); parent.addView(view, index, lp); } // ---------------------------------------- // forward all lifecycle events to MapView // ---------------------------------------- @Override public void onResume() { super.onResume(); if (mMapView != null) mMapView.onResume(); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (mMapView != null) mMapView.onSaveInstanceState(outState); } @Override public void onPause() { super.onPause(); if (mMapView != null) mMapView.onPause(); } @Override public void onLowMemory() { super.onLowMemory(); if (mMapView != null) mMapView.onLowMemory(); } @Override public void onDestroy() { super.onDestroy(); if (mMapView != null) mMapView.onDestroy(); mMapView = null; } } 。您可能会循环遍历linsolve()的每个值以生成这些方程式。