C++ :: Trapezoidal Method Differential Equation

May 11, 2013

I am working on a program to find the value of the current in a coil. This value satisfies the following equation:

y'=sin(2t)-[(ey-1)/(ey+1)]

which is of the form y'=f(t,y)

I know that in order to solve this I need to use the trapezoidal method to solve a differential equation, the formula is:

yn+1=yn+.5*h(f(tn,yn)+f(tn+1,yn+1) where h=tn+1-tn

I have found examples of the standard trapezoidal method but I do not think they will work because of the difference in the formulas.

View 2 Replies


ADVERTISEMENT

C++ :: Finite Difference Method For Partial Differential Equations?

Nov 10, 2013

Calculated by the explicit scheme. Produces some very large numbers.

task:

[math] U_t = 3 (1,1-0,5 x) U_ {xx} + e ^ t-1 [/ math]
[math] U (0, t) = 0 [/ math]
[math] U (1, t) = 0 [/ math]
[math] U (x, 0) = 0.01 (1-x) x [/ math]

Need to find a solution with accuracy [math] 0.0001 [/ math] on the interval [math] T = 1 / a ^ *, where a ^ * = max a (x, t) [/ math] Plot graphs of functions [math] u (x ^ *, t), u (x, jt ^ *) [/ math] where [math] x ^ * = 0.6, t ^ * = T/10, j = 1,2,4 [/ math]

explicit difference scheme is as follows:

([math] $ u_t ^ {j +1}-u_i ^ j) / tau = 3 (1,1-0,5 x_i) (u_ {i +1} ^ {j}-2u_i ^ j + u_ {i -1} ^ j) / h ^ 2 + e ^ {t_j} +1 $ $ [/ math]

code of the program:

int main ( void ) {
setlocale(LC_ALL, "rus");
int I = 10, J = 30, i, j;
double T = 1.0/ pow(3.3, 0.5), h_x = 1.0/ I, h_t = T/ J, epsilon = h_t + pow(h_x, 2), c;
double **u = new double *[I + 1];
for (i = 0; i <= I; i++) u[i] = new double [J + 1];

[code]....

displays the following:

[URL]

View 2 Replies View Related

C/C++ :: Trapezoidal Motion Profile Using Discrete Method?

Mar 9, 2015

I'm trying to program an arduino to generate a Trapezoidal Motion Profile to control a DC motor with a quadrature encoder.

Essentially, the user will input the desired Target Position, Max Velocity and Acceleration (decel = -accel) and the code will calculate the target position versus time which will then be compared with the actual position. The result will then be subject to a PID calculation

My initial assumption was that I could use basic Newtonian physics to determine position (i.e. PT = P0 + V0T + 1/2AT2, VT = V0 + AT). However, after reading through documentation for pre-existing motion controllers, I discovered that the prevalent method was to use a discrete time method, which is as follows:

VK = VK-1 + A (A = Acceleration)
PK = PK-1 + VK-1 + A/2

I'm having a hard time understanding quite how this equation would generate the target position versus time. In the case of Velocity, it seems to just add the acceleration to the current velocity. But what about everything in between?

View 2 Replies View Related

C++ :: Finding The Root Of Equation Using Secant Method

Feb 8, 2014

I want to find the root of an equation f(x) by using the secant method [URL] .....

#include <math.h>
#include <iostream>
using namespace std;
//Define function f(x)
double f(double x, double a, double b) {
return sin((a*x)/(1+x*x))*atan(b*x)+atan(x);

[Code] ....

1) Do I have to keep the function f and RootFinderSMNew in different cpp files?

2) When compiling I get the following errors:

1>------ Build started: Project: Assignment2.1, Configuration: Debug Win32 ------
1> Find Roots Secant method.cpp

[Code] .....

What am I doing wrong ?

View 1 Replies View Related

C :: Trapezoidal Approx Of An Integral

Aug 2, 2013

One of my last programs to write was to use the trapezoidal rule to approx. the definite integral defined in the program. It works, now i am looking for ways to improve this code, if there are any.

Code:
#include<stdlib.h>#include<stdio.h>
#include<math.h>
double integral (double x);
int main(void){

[Code] ....

the output is simple:

Code: ssma-imac:ENG-3211 ssma$ ./integralThe integral of x^2 Sin(x) dx from 1 to 5 is -18.953841

And yes this is a very good approximation of the actual integral.

View 9 Replies View Related

C :: Trapezoidal Rule - Math Library

Mar 22, 2013

I am new to c programing and I had spend 2 days on a program and I can't fix the error:

Code] ....
gcc Test.c -o Test.exe
/tmp/ccZkbk0V.o: In function `f':
Test.c:(.text+0x2f): undefined reference to `sqrt'
collect2: ld returned 1 exit status

Tthe program I am working in is:

#include <stdio.h>
#include <math.h>
int f(int x){
return (sqrt(4.0 - x*x));

[Code] .....

View 2 Replies View Related

C++ :: Undefined Reference To (method Name) When Accessing Method In Static Library

Jan 17, 2013

I've been trying for more than one month to access a method found in a library called libcocosnas_static.a. I'm using Cocos2d-X version 2.0.4. The library has been used many times by my company to make games using cocos2d-1.0.1-x-0.12.0 without any problem.

This is what I've done:
1- I added the include paths of the library to both eclipse and Android.mk
2- Included the .h file using #include "NASPlatformUtil.h"
3- Added the libcocosnas_static.a file to the proj.androidobjlocalarmeabi folder
4- Added "LOCAL_WHOLE_STATIC_LIBRARIES += cocosnas_static" to the Android.mk file
5- Called the function using: NASPlatformUtil:: openUrl("http://xxx.xxx.com/");

I can right click on the function, click Open Declaration and get it without any problem, but the compiler keeps on giving me that dreaded error...

View 3 Replies View Related

C++ :: How To Get The Value Of Variable From Equation

Mar 25, 2013

how to take two variables with values such as a 1; and b 2;. Now you take cout << a + b; and you will get 3, but I want to somehow have a 1; b 2; and c num; then have a + b = c. So what ever I have the user input is for a and be added together will become the value of the c variable.

View 1 Replies View Related

C++ :: Pass Method Of Derived Class As Parameter To Another Method In Base Class?

Feb 2, 2015

I have a question similar to the one here: [URL] .....

The main difference is I would like to pass a method of derived class as a parameter to some other method in its template base class.

template <typename BaseType>
class Base {
public:
typedef void (Base::*Callback)(int A);

[Code] .....

The above is an example which does not compile. My compiler complains that the two BaseMethod() calls in DerivedMethod() are invalid uses of non-static member function.

Is this not possible to do, or is my syntax simply wrong? All I want is to be able to pass as an an argument to a method in the base class from the derived class some callback as a variable for the base class to invoke later.

View 2 Replies View Related

C :: Quadratic Equation - ID Returned 1

Oct 18, 2013

This is my code:

Code:
#include <math.h>
#include <stdio.h>
int main(void) {
float a,b,c,root_1,root_2;
printf("Please enter value a from the quadratic equation

[Code] ......

And I keep getting this error:

Code:
/tmp/ccgtUIun.o: In function `main':
assign345.c:(.text+0xc7): undefined reference to `sqrt'
assign345.c:(.text+0xef): undefined reference to `sqrt'
collect2: ld returned 1 exit status

View 5 Replies View Related

C :: How To Get Values From The User And Add Them To Equation

Oct 30, 2014

I have a small project for school due today but i cant get my head around programming

Ive to create a program where ive to get the values from the user and add them to an equation. I have also to add a selection statement where it will ask for the material being tested which will have its value set in the program.

View 4 Replies View Related

C++ :: Distance Between 2 Points Equation

Apr 14, 2013

Write a program that creates the output shown in the Output Layout section below. The program should create 2 points with x and y coordinates as integers, prompt the user to input the x and y values for one of the points and randomly set the other (-99 to 99 range) and output the length of the radius line segment and the area of the circle that radius defines. The program should then end. Include an SDM for the program and any other appropriate documentation.

Special Calculations:
Distance between 2 points equation:
√((p0x – p1x)2 + (p0y – p1y)2) (This requires use of the math library)

Output Layout: (bold text represents user input)

Please enter the location of your first point.
Enter a value from -99 to 99 for your x coordinate: -2
Enter a value from -99 to 99 for your y coordinate: 17

The location of your second randomly set point.
Your x coordinate: 45
Your y coordinate: -89

The length of the radius line segment from point one to point two is 115.
The area of the circle with a radius of 115 is 41546.33.

Other:

int pAx;
int pAy;
int pBx;
int pBy;

View 3 Replies View Related

C++ :: Quadratic Equation - Output Is NAN

Jul 4, 2014

soo quadratic equation solver. output is "x=nan x=nan".

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//prototyping
double ans_1(double,double,double)

[code].....

View 2 Replies View Related

C/C++ :: Optimizing Equation For Cases Of 0

Feb 19, 2015

I'm writing an algorithm on a microcontroller in C.

One of the iterations that takes a long time involves the following equation, summing the product of pairs of variables:

signed char VarA;
signed char VarA;
signed long VarA;
Total+=VarA*VarB;

The vast majority of cases, at least one of the variables VarA and VarB will be 0, so nothing will be added to Total.

Is there a way to check for this condition which might give me a performance increase over doing a lot of multiplying-by-zeros?

View 6 Replies View Related

C :: Program To Solve The Quadratic Equation

Feb 3, 2013

I am creating a program that solves the quadratic equation ax^2 + bx +c.

I have this program almost complete except the output of the equation in the function called display_quadratic. I need the program to display the variables a,b,c in the equation ax^2 + bx + c but I am having 2 problems. My first problem is that I cannot get the right addition and subtraction signs for the equation.

For instance, if the program had the values for a,b,c as 2,2,3

it will display 2x^2 2x 3

How can I get it to display 2x^2 + 2x + 3? or if it was negative like 2x^2 - 2x - 3?

My next question is how do I get to not display the coefficients that are 1?

I had an if-else statement but no matter what I created it would overlap with another statement and print out twice. Here is the code:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void display_quadratic (float a, float b, float c);
float root1(float a, float b, float c);

[Code] ......

View 2 Replies View Related

C :: Multiple Roots For Quartic Equation

Sep 10, 2013

I am having trouble understanding how this loops would work. Give the function (x*x*x*x) - (10*x*x*x) + (35*x*x) - (50*x) + 24 Write a program that will use bisection method to find the roots of this function. Define lower limit and upper limit (e.g. -1.05 and 6.05) Starting at the lower limit step along the X axis at intervals of 0.1 for H calculating the function values f(x) and f(x +h), then f(x+h) and f(x+2h) until the upper limit is exceeded. If sign of the function value changes this indicates a root between ranges. Apply bi sectional method to this range until root has been found with an epsilon of 0.000001, then continue on until upper limit has been exceeded and all 4 roots found. If the function is within 0.000001 of zero then root has been found therefore no need for bi sectional method.

Code:

#include "stdafx.h"
#include "math.h"
#define H 0.1
#define epsilon 0.000001
double F(double x);
int main(void)

[code]....

So we have a function and a range. Program requires to work along the X axis at 0.1 increments until it reaches a point where the value changes from positive to negative or negative to positive. Then apply bisection method within that range to a given accuracy then print that root. Then continue on X axis until the next change of sign is found.

View 8 Replies View Related

C++ :: Calculating Equation Using Expression Builder

Jan 22, 2014

How do to calculate the following equation"5+((56+8)/2)" using expression builder

Note: the equation may change "50+((26+8)/12)"

View 1 Replies View Related

C++ :: Quadratic Equation - No Matching If Statement

Oct 7, 2013

This is my code for the quadratic equation. It keeps telling me that my else is illegal since no matching if statement and my else statement is missing a statement

#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
int main() {
string Name;

[Code] .....

View 3 Replies View Related

C++ :: Program Returning NaN For Quadric Equation

Mar 29, 2013

My program is returning NaN even though the value in square root function is not negative -1*b + ((sqrt(pow(b,2) * -4 *(a*c))) / 2).

x = 10;
y = -1;
z = 1;

Heres the program:

main.cpp:

#include <iostream>
#include "Quad.h"
double x,y,z; // variable x = 'a', variable y = 'b' and variable z = 'c'.

[Code] ....

I would like it return the answer and not "NaN".

View 10 Replies View Related

C++ :: Allowing For User Input Of Equation To Be Evaluated

May 14, 2014

I've written a program that finds the maximum of a function. I now want to change it a little so that instead of evaluating the function y=x^2-7x-18, the program will ask the user to input an equation and then evaluate that equation. I'm really not sure of how to do so.

#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main() {
int a, b, delta, x, y;
double max= -1.8 * pow(10, 308);

[Code] .....

View 3 Replies View Related

C++ :: Enter Equation All At Once Instead Of Prompting For Each Piece Separately?

Mar 4, 2014

How do I enter the equation all at once instead of prompting for each piece separately?

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

[Code].....

View 4 Replies View Related

C/C++ :: Quadratic Equation Solver - Simplification Function

Jul 6, 2014

So, I successfully made a program that will perform the quadratic equation on three numbers, imaginary or real. however, i am now trying to simplify the result, as to get rid of the "/2a" on the bottom. Hence the simplify() function. I just started to create the simplification function, and am attempting to divide the imaginary part of the solution as well as the real part of the solution by 2a. Somehow, it gives the error, "error:invalid operands of types 'int' and 'double *' to binary 'operator*'" on lines 105 and 106. I suspect it has to do with the pointers and references that i am passing as parameters. Also, just an aside, I have never actually seen "/=" be used. It can be, right? I know "+=" can be.

#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>//simplify the answer
using namespace std;
int count=0;
//prototyping
double ans_1(double,double,double);

[Code] ....

View 5 Replies View Related

Visual C++ :: Arrays - Solve Equation Using All Volume Values

Dec 22, 2012

I am using matlab R2o11 in which the programming medium is c++. I am having these variables=

T=373 t0 376
V=0.09 to 1
P=T/V

I just need a result showing ... First it should take T=373 and solve the equation using all volume values. Then it takes another temperature and do the same.

View 4 Replies View Related

C++ :: Equation That Determines The Lowest Possible Cost For Laying Power Line

Apr 9, 2013

I need an equation that determines the lowest possible cost for laying power line.

The variables are as follows:

1. The width of a river
2. The distance a factory is downstream from a station on the other side of the river.
3. The cost for laying line underwater.
4. The cost for laying line on land.

All these variables will be user input each use of program.

View 4 Replies View Related

C++ :: Method To Loop Through Network IPs

Nov 25, 2013

This problem relates to a program i am developing to ping all hosts on a network.

So far I've managed to access a PostgreSQL database to retrieve a CIDR network address e.g. 192.168.52.14/24.

I have then managed to mask the bits to get the network address.
So for e.g. above its 192.168.52.0

I now need some kind of algorithm to loop through available hosts so from.

192.168.52.0 - 192.168.52.255

I have got as far as deriving the network and separating it into an int array

So I have : ip_start[]= {192,168,52,0}

View 1 Replies View Related

C++ :: Using Reference With Virtual Method

Mar 19, 2013

#include <iostream>
using namespace std;
struct A {
virtual void f() { cout<<"A
"; }
};

[code]...

I would expect that both examples 2 & 3 will give me the same result.I tried to figure it out but I could not. Both are references of a base class type, that get a derived object.

Q1 : why is the difference between them ?

As I see it, its kind of a mix between pointer - which in case of virtual method that was override in derived class - would give me the derived method (e.g. "B") and between regular object - which in case of virtual method that was override - would give me the specific method (Still "B"). So, example 2 "use" it as a regular object and example 3, "use" it as pointer.

Q2 : How should I refer to it ? I am using VS2008.

View 12 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved