[go: nahoru, domu]

Skip to content

sheraadams/Calculus-Helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Calculus Helper Android App

GitHub Static Badge Static Badge

About the Project

This app was programmed with Java in Android Studio. It is compiled with SDK 34 and targets SDK 24 - 33. It is a helpful tool for mathematical modeling and for quick conversion between integrals and derivatives. It is inspired from one of my first projects which I originally programmed with Python and Tkinter.

Screenshots

image

Calculations

We calculate the derivative as follows:

    void derivative() {
        try {
            double coefficientValue = Double.parseDouble(coefficient.getText().toString());
            double powerValue = Double.parseDouble(power.getText().toString());

            double answerCoefficient = coefficientValue * powerValue;
            double answerPower = powerValue - 1;

            coefficientAnswer.setText(String.valueOf(answerCoefficient));
            powerAnswer.setText(String.valueOf(answerPower));

        } catch (NumberFormatException e) {
            // Handle parsing errors
            Log.e("Error", "Invalid input");
        }
    }

Similarly, we calculate the inegral:

    void integral() {
        try {
            double coefficientValue = Double.parseDouble(coef![image](https://github.com/sheraadams/Calculus-Helper/assets/110789514/7ec2e5ae-b240-45d3-96c4-b8b71f18b56e)
ficient.getText().toString());
            double powerValue = Double.parseDouble(power.getText().toString());

            double answerPower = powerValue + 1;
            double answerCoefficient = coefficientValue / answerPower;

            powerAnswer.setText(String.valueOf(answerPower));
            coefficientAnswer.setText(String.valueOf(answerCoefficient));

        } catch (NumberFormatException e) {
            // Handle parsing errors
            Log.e("Error", "Invalid input");
        }
    }

Plotting the data

We can plot the data with the help of the MPAndroidChart library. Once we set up some preferences and plot configurations, we can calulate our data points:

    private List<Entry> generateQuadraticData(double coefficient, double power) {
        List<Entry> entries = new ArrayList<>();

        // increment by .1 to smooth out the curves
        for (float x = -20; x <= 20; x += 0.1) {
            float y = (float) (coefficient * Math.pow(x, power));
            entries.add(new Entry(x, y));
        }

        Log.d("GraphActivity", "generateQuadraticData entries: " + entries);
        return entries;
    }

We plot the data with the following function:

    private void setData(LineChart chart, List<Entry> dataSet, String label, int lineColor) {
        LineDataSet lineDataSet = new LineDataSet(dataSet, label);
        lineDataSet.setColor(lineColor);
        lineDataSet.setLineWidth(2f);

        LineData lineData = new LineData(lineDataSet);
        chart.setData(lineData);

        // Refresh chart
        chart.invalidate();
    }

Proudly crafted with ❤️ by Shera Adams.

About

Android Calculus Helper App

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published