473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

finding arc length of a curve

hi guys, I just wrote the below code, but matlab gives me the different result. what is the problem with the below code? I need your comments. Thanks in advance


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(){
int i;
long double y[20000],yder[20000],t,syder[20000],sumx;
for(i=1,t=1;i<=10001,t<=2;i=i+1,t=t+0.0001){
y[i]=((1/6)*pow(t,3))+(0.5/t);}
for(i=1;i<=10000;i++){
yder[i]=(y[i+1]-y[i])/0.0001;
}
for(i=1;i<=10000;i++){
syder[i]=pow(1+(yder[i]*yder[i]),0.5);}
sumx=0;
for(i=1;i<=10000;i++){
sumx=sumx+((syder[i]+syder[i+1])*0.0001/2);
}
printf("\n%Lf",sumx);
getch();
}
Sep 19 '15 #1
1 1570
weaknessforcats
9,208 Expert Mod 8TB
It looks like the type of t is int so t=t+0.0001 won't work.

Also 1/6 is always 0. There are no sixes in 1. Maybe try 1.0/6.0 to tell the compiler to use floating point division instead of integer division.

Never mix integer and floating point. It's all floating point or all integer. Otherwise these creepy discrepancies will pop up as the compiler tries to figure out what you want. Like ,t=t+0.0001 causes t to be converted to a double, the .0001 is added to a sum which is double. Then the sum is truncated back to int to stuff it back in t. You should be getting a warning about truncation and possible loss of data.
Sep 20 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: nmukh1 | last post by:
Hey guys, I'm trying to optimize a program that measures the length of a curve. Suppose I define a function f and I have two bounds and am trying to find the arc length. The familiar calculus...
0
by: James Dean | last post by:
This may not be related to this newsgroup but i thought i would ask anyway. I am doing a project in C#. I would like to know of any good sites or information about Line and curve fitting. I would...
0
by: fripper | last post by:
I have a VB .Net 2003 program that I am upgrading to VB 2005. It includes a data structure that defines an object containing a number of fixed length (stirng) fields. Somehting like the...
2
by: Extremest | last post by:
Here is the code I have so far. It connects to a db and grabs headers. It then sorts them into groups and then puts all the complete ones into another table. Problem I am having is that for some...
1
by: Mike Heywood | last post by:
Hi, I am currently trying to automate a process that I have been studying the manual results from for a while. The process simply identifies events that meet certain criteria and at the moment...
26
by: K.J.Williams | last post by:
Hello, A friend and I want to learn PHP but we have two totally different programming backgrounds. I have experience with procedural programming in C, and he has experience with Visual BASIC....
1
by: pedalpete | last post by:
I have a bunch of events which I extract from my database, some of these events extend over a night, some take place during a single day. In the database I have the start/end times of the event,...
2
vdraceil
by: vdraceil | last post by:
Hi,i'm using vb6.I have a command button which when clicked opens VLC Media Player and plays a specific file in it in full screen mode. Now i want the player to close itself after playing the file....
3
by: cmwb2000 | last post by:
Hi I am trying to test to see if there is a link between the curve of a mouses movement and the length from the ball to the wrist (pivet point). I am recording a series of points as the mouse...
3
by: Maxood | last post by:
I have the following code: int* y = new int; where n's value will be provided by the user at runtime. I need to know the total memory size that i have allocated to y. What function i will...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.