Question

In: Computer Science

1. Solve a function (e​ .g.​, y(x) = sin(x) / (sin(x/10) + x/10) for many different...

1. Solve a function (e​ .g.​, y(x) = sin(x) / (sin(x/10) + x/10) for many different values of x between a user-defined min and max, and store the values in a list. Also, print the maximum value of y(x) for the given range.

2. Find the list in a list-of-lists whose sum of elements is the highest, and print the sum and list to the user.

e.g., [[1, 2], [2, 5], [3, 2]] → [2,5] with a sum of 7.

Solutions

Expert Solution

I am writing the code in C++ and also after // this symbol i will explain about that line.

question no. 1:

#include<iostream>

#include<cmath>        // this library function will gives sin value

#include<algorithm>

using namespace std;

int main()

{

    double max,min,temp=0;    // sin value always in double type data

    double list[30];    // declaring array for storing the y(x) function value

    int l=0;

    int n;

    cout<<"Enter the minimum value of x ";

    cin>>min;                                                                //taking data from user input

    cout<<"Enter the maximum value of x ";

    cin>>max;

    for(int x=min;x<=max;x++)

    {

        temp= sin(x)/(sin(x/10)+x/10);                 // calcuating y(x) in the range of min to max value

        list[l]=temp;

        cout<<temp<<endl;

        l++;

        temp=0;

    }

    n=sizeof(list)/sizeof(list[0]);         // sorting algorithm to sort array in decending order

    sort(list, list+n,greater<int>());

    cout<<"The maximum value of y(x) is "<<list[0];

    return 0;

}

Question no.2:

#include<iostream>

#include<algorithm>

#include<math.h>

using namespace std;

int main()

{

    int list[3][2]={{1,2},{2,5},{3,2}};    // declaring list in 2d array

    int sum=0;

    int temp[3];     // declaring 2nd array for store sum of each pair

    for(int i=0;i<3;i++)

    {

        for(int j=0;j<2;j++)

        {

            sum=sum+list[i][j];    // adding the pair

        }

        temp[i]=sum; //storing the sum into temp array list

        sum=0;

    }

    int n=sizeof(temp)/sizeof(temp[0]);

    sort(temp,temp+n);    // now here sorting of array increasing order

    cout<<"highest sum is "<<temp[2];   now printing n-1 element which will be highest.

    return 0;

}


Related Solutions

2. Solve a function (e.g., y(x) = sin(x) / (sin(x/10) + x/10) for many different values...
2. Solve a function (e.g., y(x) = sin(x) / (sin(x/10) + x/10) for many different values of x between a user-defined min and max, and store the values in a list. Also, print the maximum value of y(x) for the given range.?
Given the funtion g(x,y) = (e^x)(y)+sin(x/y). 1. Find the linearization of g(x,y) at the point (1,2)....
Given the funtion g(x,y) = (e^x)(y)+sin(x/y). 1. Find the linearization of g(x,y) at the point (1,2). 2. Estimate the value of g(1.01, 1.99).
Solve differential equation: y'+y=sin(x)
Solve differential equation: y'+y=sin(x)
Consider the function given as example in lecture: f(x, y) = (e x cos(y), ex sin(y))...
Consider the function given as example in lecture: f(x, y) = (e x cos(y), ex sin(y)) (6.2) Denote a = (0, π/3) and b = f(a). Let f −1 be a continuous inverse of f defined in a neighborhood of b. Find an explicit formula for f −1 and compute Df−1 (b). Compare this with the derivative formula given by the Inverse Function Theorem.
Write your own MATLAB code to solve the system 10 − x + sin(x + y)...
Write your own MATLAB code to solve the system 10 − x + sin(x + y) − 1 = 0 8y − cos2 (z − y) − 1 = 0 12z + sin(z) − 1 = 0 using a residual tolerance of 10^−6 and the initial guess, ~x 0 = [0.1, 0.25, 0.08]^T . Print out the values for x, y and z for each iteration in a table similar to the one you created for the problems of the...
solve y' +(x+2/x)y =(e^x)/x^2 ; y(1)=0
solve y' +(x+2/x)y =(e^x)/x^2 ; y(1)=0
Solve the differential equation y'''+y''+y'+y=sinx+e^x+e^{-x}
Solve the differential equation y'''+y''+y'+y=sinx+e^x+e^{-x}
Use logarithmic differentiation to find the derivative of the function: y= sqrt(x)e^(x^3) (x^4 +1)^9 sin x
Use logarithmic differentiation to find the derivative of the function: y= sqrt(x)e^(x^3) (x^4 +1)^9 sin x
subject:engineering mathematics solve [cos(x+y)-sin(x+y)]dx-sin(x+y)dy=0,is the ODE exact?Find an integrating factor and solve the ODE.
subject:engineering mathematics solve [cos(x+y)-sin(x+y)]dx-sin(x+y)dy=0,is the ODE exact?Find an integrating factor and solve the ODE.
Solve by variation of parameters: A. y"−9y = 1/(1 − e^(3t)) B. y" +2y'+26y = e^-t/sin(5t)
Solve by variation of parameters: A. y"−9y = 1/(1 − e^(3t)) B. y" +2y'+26y = e^-t/sin(5t)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT