numerical-methods

Numerical integration Legendre Polynomials MATLAB

只愿长相守 提交于 2019-12-13 04:16:09
问题 The Legendre polynomials are implemented in MATLAB as vectors, where you also get all the associated Legendre polynomials evaluated at a particular point x. Thus, I don't know how I can use these functions inside an integral. My question is: How can I evaluate the (NUMERICALLY CALCUALTED(!)) integral from -1 to 1 over the n-th Legendre polynomial in Matlab? EDIT: As I received an answer that is really not what I want: I want to use the implementation of the Legendre polynomials in MATLAB

How to draw graph of Gauss function?

风流意气都作罢 提交于 2019-12-12 15:08:28
问题 Gauss function has an infinite number of jump discontinuities at x = 1/n, for positive integers. I want to draw diagram of Gauss function. Using Maxima cas I can draw it with simple command : f(x):= 1/x - floor(1/x); plot2d(f(x),[x,0,1]); but the result is not good ( near x=0 it should be like here) Also Maxima claims: plot2d: expression evaluates to non-numeric value somewhere in plotting range. I can define picewise function ( jump discontinuities at x = 1/n, for positive integers ) so I

What is the numerical stability of std::pow() compared to iterated multiplication?

允我心安 提交于 2019-12-12 11:02:53
问题 What sort of stability issues arise or are resolved by using std::pow() ? Will it be more stable (or faster, or at all different) in general to implement a simple function to perform log(n) iterated multiplies if the exponent is known to be an integer? How does std::sqrt(x) compare, stability-wise, to something of the form std::pow(x, k/2) ? Would it make sense to choose the method preferred for the above to raise to an integer power, then multiply in a square root, or should I assume that

The precision of a large floating point sum

不羁的心 提交于 2019-12-12 10:45:41
问题 I am trying to sum a sorted array of positive decreasing floating points. I have seen that the best way to sum them is to start adding up numbers from lowest to highest. I wrote this code to have an example of that, however, the sum that starts on the highest number is more precise. Why? (of course, the sum 1/k^2 should be f=1.644934066848226). #include <stdio.h> #include <math.h> int main() { double sum = 0; int n; int e = 0; double r = 0; double f = 1.644934066848226; double x, y, c, b;

Getting y from x co-ord for cubic bezier curve, fast Newton-Raphson method

老子叫甜甜 提交于 2019-12-12 05:36:19
问题 Given the points of a Bezier curve (P0, P1, P2, P3) in 2D, I would like to find the y co-ordinate for a given x co-ordinate. The problem is well defined because of the following restrictions: P0 = (0,0), P3 = (1,1) P1 = (t, 1-t) for t between 0, 1 P2 = 1 - P1 (x and y) I have the following function to calculate the answer, having put in all the restrictions above into the Bezier curve formula here CubicBezier.html. I am using Newton-Raphson to work out the parameter of the point I want, and I

Euler's Method in java

☆樱花仙子☆ 提交于 2019-12-12 03:23:14
问题 I have written an Euler's Method code to find an approximate value for x(10) and compare it to the value of x(10) given by the exact solution given in separable ODE. However, my code displays a chaotic number for x(10). Can you please identify a major error. Thank you. //@(#)euler.java //This method attempts to find solutions to dx/dt = (e^t)(sin(x)) via //Euler's iterative method and find an approximate value for x(10) import java.text.DecimalFormat; public class euler { public static void

A code for finding one root of fifth degree polynomial

陌路散爱 提交于 2019-12-12 03:14:02
问题 I'm trying to write a code that asks from the user to give 5 coefficients for a 5th-degree polynomial, and it also asks to give a range (two values) that the programs checks if there is a solution in it or not (I'm asked to find only one), and the solution must be an integer, while the coefficients can be floats. I'm thinking of writing a code that runs over every integer in the range and substitute it in a description of a polynomial than I define, and check if its equal to zero, but I got

MATLAB/OCTAVE- Numerical integration of an integrand containing terms obtained from numerical solution of a system of ODE

荒凉一梦 提交于 2019-12-12 01:37:52
问题 I want to calculate the following integral on Octave(or Matlab): However, I don't have an explicit expression for H and K. The H and K are actually numerical solutions of the following differential equations. The initial conditions of h,k, dh/dr, and dk/dr are 0,1,1/2,0 respectively. How do I go about doing this? Can I solve it directly somehow, or do I need to find the numerical solutions to H and K first, find a polynomial approximation, and then integrate? I am completely new to Matlab and

Behavior of Scala for/comprehension implicit transformation of numerical types?

孤者浪人 提交于 2019-12-12 00:53:03
问题 I'm trying to understand the behavior of Scala for-loop implicit box/unboxing of "numerical" types. Why does the two first fail but not the rest? 1) Fails: scala> for (i:Long <- 0 to 10000000L) {} <console>:19: error: type mismatch;<br> found : Long(10000000L) required: Int for (i:Long <- 0 to 10000000L) {} ^ 2> Fails: scala> for (i <- 0 to 10000000L) {} <console>:19: error: type mismatch; found : Long(10000000L) required: Int for (i <- 0 to 10000000L) {} ^ 3) Works: scala> for (i:Long <- 0L

Determining regression coefficients for data - MATLAB

只谈情不闲聊 提交于 2019-12-11 19:33:01
问题 I am doing a project involving scientific computing. The following are three variables and their values I got after some experiments. There is also an equation with three unknowns, a , b and c : x=(a+0.98)/y+(b+0.7)/z+c How do I get values of a,b,c using the above? Is this possible in MATLAB? 回答1: This sounds like a regression problem. Assuming that the unexplained errors in measurements are Gaussian distributed, you can find the parameters via least squares. Basically, you'd have to rewrite