Question

IW7-3] Write a code which prints the dynamical matrix for a chain of N masses co by springs k to a file. Write it in a way th

***** please answer all questions and type it all please, specially the code you create. I really need the help. Thank you so much, if you help by answer all questions, ill give you a good rating! The language used is C

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

int main()
{
   int N,k; //declaring N and k
   printf("Enter N: ");
scanf("%d",&N); //taking N value from the user
printf("Enter k: ");
scanf("%d",&k); //taking k value from the user
int dynmatrix[128][128]; //declaring integer matrix

for(int i=0;i<128;i++){
   for(int j=0;j<128;j++){ // Assigning zeroes to all values
       dynmatrix[i][j]=0;
   }
}

for(int i=0;i<128;i++) // diagonal elements= 2k
   dynmatrix[i][i] = 2*k;


for (int i=0; i<127; i++) //here we have to go till 126 index because wew are assigning at i+1
   dynmatrix[i][i+1]= -k;   


for (int i=1; i<128; i++) //here we have start with index 1 because wew are assigning at i-1
   dynmatrix[i][i-1]= -k;


for(int i=0;i<N;i++){   
   for(int j=0;j<N;j++){ //This loop prints NxN matrix with the assigned values
       printf("%4d ", dynmatrix[i][j]);
   }
   printf("\n");
}
return 0;
}

Activities Terminal Mon 13:19 Ink.c.-Sublime Text (UNREGISTERED) File Edit Selection Find View Goto Tools Project Preferences

Add a comment
Know the answer?
Add Answer to:
***** please answer all questions and type it all please, specially the code you create. I really need the help. Thank you so much, if you help by answer all questions, ill give you a good rating! Th...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can you please help me with this question. Much appreciated. So I have a sample code,...

    Can you please help me with this question. Much appreciated. So I have a sample code, but we need to change the code in a way that fits the problem. A planar slab of material is initially at a temperature of 300 K. At the time t=0, microwave radiation is directed at the material, leading to internal heat generation that is uniform within the material. The sides of the slab experience negligible heat losses and a water bath maintains the...

  • need help on all parts please and thank you (e) What is the correct output of...

    need help on all parts please and thank you (e) What is the correct output of this code? (2 pts) >>> def func(x): >>> res = 0 >>> for i in range (len (x)): res i >>> return res >>> print (func(4)) ( 4 5 ) 6 ()7 ( What could be described as an immutable list? (2 pts) () a dimple ( ) a tuple ( ) a truffle () a dictionary (g) What is the result of the...

  • I need help with number 2 and 3 thank you Please show all steps much appreciated...

    I need help with number 2 and 3 thank you Please show all steps much appreciated 2. Write the co ordinate v in R (with usual basis) in terms of the given basis S answer. 3. Determine whether the set S-$3,x, x-x spans P. Explain your

  • 2. PLEASE ANSWER ALL THESE QUESTIONS. PLEASE I REALLY NEED HELP WITH THESE THANK YOU SO...

    2. PLEASE ANSWER ALL THESE QUESTIONS. PLEASE I REALLY NEED HELP WITH THESE THANK YOU SO MUCH The table below shows position data for 8 different objects. Let WEST be the positive direction. Based on the data, determine which objects MOVED WEST THE ENTIRE TIME, which objects MOVED EAST THE ENTIRE TIME, and which objects MOVED AT A CONSTANT VELOCITY THE ENTIRE TIME. For each scenario choose all that apply At (min) 0 r4y (mm)(in) (cm)(km (yd) (mi) (m) 95...

  • I need help calculating all kf these questions. Really stuck on all of them! Thank you!...

    I need help calculating all kf these questions. Really stuck on all of them! Thank you! Year using the returns for the first three years. The next rolling ace would be calculated using the returns from Years 2. 3. and 4, and so on Using the annual returns for large company stocks and Treasury bills, calculate both the 5- and 10-year rolling average return and standard deviation. h Over how many 5-year periods did Treasury bills outreform Caree company stocks?...

  • Please program in C++ and document the code as you go so I can understand what...

    Please program in C++ and document the code as you go so I can understand what you did for example ///This code does~ Your help is super appreciated. Ill make sure to like and review to however the best answer needs. Overview You will revisit the program that you wrote for Assignment 2 and add functionality that you developed in Assignment 3. Some additional functionality will be added to better the reporting of the students’ scores. There will be 11...

  • Hi I need some help on this lab. The world depends on its successfull compilation. /*...

    Hi I need some help on this lab. The world depends on its successfull compilation. /* Lab5.java Arrays, File input and methods Read the comments and insert your code where indicated. Do not add/modify any output statements */ import java.io.*; import java.util.*; public class Lab5 { public static void main (String[] args) throws Exception { final int ARRAY_MAX = 30; // "args" is the list of tokens you put after "java Project3" on command line if (args.length == 0 )...

  • Please type your answer so I can read it, and I just need help for question...

    Please type your answer so I can read it, and I just need help for question one ( Hypothesis ) don't worry about the rest of them. Experimental plan: You are provided with a standard solution of albumin, which is 60 g/L. This is known as the primary standard. Your task is, complete the table below to prepare 3 other standards with 15, 30 and 45 g/L concentration, respectively with the final volume of 1 mL. These are known as...

  • Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And...

    Please Use C++ Language. Thank you. Please I need the actual code. Donot post psudocode!! ​And also I have codes but just donot work so make sure that it works. Requested files: CrosswordGenerator.cpp, CrosswordGenerator.h, CrosswordGenerator_test.cpp CrosswordGenerator - Write a program that helps to generate a crossword puzzle by organizing words that share letters.   For this assignment, you will write a program that forms the basis of a crossword puzzle generator. In order to create a crossword puzzle you need to...

  • Java I just need the answer to the questions, not the whole implemented code please You have an object of the RandomAccessFile class named empRaf. It refers to a physical file that contains a company&...

    Java I just need the answer to the questions, not the whole implemented code please You have an object of the RandomAccessFile class named empRaf. It refers to a physical file that contains a company's employee records. Each employee record has: an int field named empID which points to its location in the file a 20 character last name a 15 character first_name a hire date stored as an int a 3 character job code The empID values begin at...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT