question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Curve creation including y variable

See original GitHub issue

I have this script:

from manimlib.imports import *
import numpy as np 

class graphx(GraphScene):
	CONFIG={
		"x_min": -4,
		"x_max": 4,
		"y_min": -2,
		"y_max": 2,
		"x_axis_label": "$x$",
		"y_axis_label": "$y$",
		"graph_origin": 0.5 * DOWN + 0 * LEFT,
	}

	# Defining graph functions 
	def show_function_graph(self): 
		self.setup_axes(animate=True)
		# Math function
		def func(x):
			return x**3 + 497*x + 1768
		#sin graph
		graph_sin=self.get_graph(func,x_min=-5, x_max=5)
		graph_sin.set_color(RED)
		# Cos graph

		
		# Play grapgs
		self.play(ShowCreation(graph_sin,), run_time=3)
		self.wait(1)
		# self.play(ShowCreation(graph_cos), run_time=3)



	# Defining construction
	def construct(self):
		self.show_function_graph()

and what I am trying to do is to show this curve: y^2 = x^3 + 497*x + 1768. Have tried to math.sqrt(x**3 + 497*x + 1768), but it doesn’t work. Is there any way that I can include y variable?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
NeoPlatocommented, Sep 18, 2020

Mate

Push the code block containing the method implicit curve one level of indentation lower. The way I see it you’ve placed it in the construct block hence it couldn’t be initialized as an attribute of the scene class.

1reaction
NeoPlatocommented, Sep 17, 2020

Your dilemma needs some serious math to be solved. Let’s dive in.

We start off by admitting that computers exist and if you’re going to hassle a graph in Manim at least get some help. Say, Desmos for example.

Your example is wayyy too complicated so I’m shrinking it down a bit.

image

Great! Now let’s think through this a bit.

For any x value you give me, can I determine the y value that is on that graph? Let’s see!

image

Yes…and no. Not all x values work(orange line) and even for those that do(purple line) you have to account for two solutions which is not very helpful.

The reverse is feasible though. Any y value gives you one and only one x value, Except it pushes you to do something less efficient and objectively worse: solving this equation:

x**3 + 2x + 1 = something

And not just for any specific something, which is doable by hand, but every point in the y range available. The good thing about this, however, is being able to represent that as a parametric equation which is already Manim programmed.

This is a good time to tell you that Desmos is an already existing and very awesome graphing calculator and for this case using Manim is overkill. But you asked the question and I have decided to answer.

image

image

You tell me if that’s worth the effort.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Curve Fitting using Linear and Nonlinear Regression
Curve fitting is the process of specifying the model that provides the best fit to the curve in your data. Learn how using...
Read more >
Dependent and Independent Variables - YouTube
This math and science video tutorial shows you how to identify the dependent and independent variables so you which data to plot on...
Read more >
How do you sketch level curves of multivariable functions?
7:52 // How to rewrite the function to graph the multivariable function? ... of x and y only and can therefore be graphed...
Read more >
Module 3.2: Curvature, Dummy Variables and Interaction
To add curvature, we simply create a new variable by squaring the quantitative independent variable, as shown in Worksheet 3.2.5. On the Excel...
Read more >
How do I include multiple independent variables or column ...
To do this, you need to use the table function. For example, suppose you plotted c0 as X and c1 as Y and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found