Writing a Program to Calculate yn+1 for n=100

  • Thread starter Thread starter nard
  • Start date Start date
  • Tags Tags
    Program Writing
AI Thread Summary
The discussion centers on writing a program to compute and display values of y and z based on a given differential equation, specifically y" = cos(t)*y + y, with initial conditions y(0) = 1 and y'(0) = 0. The program should iterate for n = 100 and store results in a file. The user provides a code snippet in C that initializes arrays for y, dy, z, and time t, using a for loop to calculate values based on the specified equations. The code successfully writes the results to a file and prints them to the console. There is a request for assistance in incorporating user-defined functions into the program, indicating a desire for improved structure and modularity in the code. The key focus is on solving the differential equation using numerical methods while enhancing the program's functionality.
nard
Messages
16
Reaction score
0
can somebody help me on writting a program that displays yo
to yn+1 when n=100 and store them in a file.
y"=cos(t)*y+y
y(0)=1
y'(0)=0
h=0.1
y'=z
z'=z'*cos(t)+y
yn+1=zn+h*zn*(cos(tn))+yn)
tn=t+nh
 
Technology news on Phys.org
i have the above using for loop without declaring any fuction,
if someone knows how to solve it including user defined function then he might be able to help me.
thank you!
the one i wrote is showed below

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
main()
{
FILE *fp;
fp=fopen("D:\\cop.txt","w");
float y[100],dy[100],z[100],h,t[100];
int i;
y[0]=1;
z[0]=0;
h=0.1;
t[0]=0;
for(i=0;i<100;i++)
{
t=t[0]*i*h;
y[i+1]=y+h*z;
z[i+1]=z+h*((z*cos (t))+y);
}
fprintf(fp,"i\tz(n+1)\t\ty(n+1)\n\n");
printf("i\tz(n+1)\t\ty(n+1)\n\n");
for(i=0;i<100;i++)
{

fprintf(fp,"%d\t%f\t%f\n",i,z[i+1],y[i+1]);
printf("%d\t%f\t%f\n",i,z[i+1],y[i+1]);
}
fclose(fp);
system("PAUSE");

}
 
Last edited:
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top