Загрузка...

Help with the lab

Thread in C/C++ created by varinok Nov 29, 2023. 192 views

  1. varinok
    varinok Topic starter Nov 29, 2023 2 Nov 4, 2020
    1) Вычислить элементы матрицы(матрицу заполнять рандомно) размером n x m по формуле

    [IMG]
    2) Вычислить элементы вектора как средние арифметические значения элементов второго и последнего столбцов матрицы.
    3) Значение произведения элементов матрицы со значением менее 10
    Только не юзайте чат гпт он хуйню выдает
     
  2. ChatGPT
    ChatGPT Nov 29, 2023 2250 Mar 14, 2023
    varinok, для решения задачи нам нужно знать значения n и m. Пожалуйста, уточни их.
     
    1. View previous comments (1)
    2. ChatGPT
      varinok, понял. Попроси пользователя ввести значения n и m, а затем я помогу решить задачу.
  3. varinok
    varinok Topic starter Nov 29, 2023 2 Nov 4, 2020
    n=4 m=5
     
  4. W223
    W223 Nov 29, 2023 Android Developer 9171 Nov 14, 2013
    Python
    import numpy as np
    import sympy as sp

    def calculate_matrix(n, m):
    matrix = np.zeros((n, m), dtype=float)
    i, j = sp.symbols('i j')
    formula = sp.log(i**2 + j**2 + 2.5, 10)**(1/3) * (i - 2.5)**j
    for row in range(n):
    for col in range(m):
    matrix[row, col] = formula.subs({i: row+1, j: col+1}).evalf()

    return matrix

    def calculate_vector(matrix):
    vector = np.mean(matrix[:, [1, -1]], axis=1)
    return vector

    def product_of_elements_less_than_10(matrix):
    filtered_elements = matrix[matrix < 10]
    product = np.prod(filtered_elements)
    return product


    n = input('Введите n: ')
    m = input('Введите m: ')


    matrix = calculate_matrix(n, m)


    vector = calculate_vector(matrix)


    product = product_of_elements_less_than_10(matrix)

    print("Матрица:")
    print(matrix)
    print("\nВектор:")
    print(vector)
    print("\nПроизведение элементов матрицы меньше 10:")
    print(product)

    C
    #include <iostream>
    #include <vector>
    #include <cmath>
    #include <numeric>


    std::vector<std::vector<double>> calculate_matrix(int n, int m) {
    std::vector<std::vector<double>> matrix(n, std::vector<double>(m));
    for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
    double base = (i+1)*(i+1) + (j+1)*(j+1) + 2.5;
    matrix[i][j] = std::cbrt(std::log10(base)) * std::pow((i+1) - 2.5, j+1);
    }
    }
    return matrix;
    }

    std::vector<double> calculate_vector(const std::vector<std::vector<double>>& matrix) {
    std::vector<double> vector(matrix.size());
    for (size_t i = 0; i < matrix.size(); ++i) {
    vector[i] = (matrix[i][1] + matrix[i].back()) / 2.0;
    }
    return vector;
    }


    double product_of_elements_less_than_10(const std::vector<std::vector<double>>& matrix) {
    double product = 1.0;
    for (const auto& row : matrix) {
    for (double elem : row) {
    if (elem < 10) {
    product *= elem;
    }
    }
    }
    return product;
    }

    int main() {
    int n, m;
    std::cout << "Введите n: ";
    std::cin >> n;
    std::cout << "Введите m: ";
    std::cin >> m;

    auto matrix = calculate_matrix(n, m);
    auto vector = calculate_vector(matrix);
    double product = product_of_elements_less_than_10(matrix);

    std::cout << "Матрица:\n";
    for (const auto& row : matrix) {
    for (double elem : row) {
    std::cout << elem << ' ';
    }
    std::cout << '\n';
    }

    std::cout << "\nВектор:\n";
    for (double v : vector) {
    std::cout << v << ' ';
    }
    std::cout << "\n\nПроизведение элементов матрицы меньше 10:\n";
    std::cout << product << std::endl;

    return 0;
    }
    ты только внимательно все проверь, сдавать то тебе все таки это) а может и защищать
     
    1. panacea
      W223, c/c++ кста раздел
    2. W223
      panacea, ебать сорян, ща перепишу
    3. gyxxidd
      W223, chat gpt такое себе, у них теми вектор в любом случае еще не было
  5. gyxxidd
    gyxxidd Nov 29, 2023 2 Nov 7, 2022
    #include <iostream>
    #include <math.h>
    using namespace std;




    int main()
    {
    int n;
    int m;
    cout << "Pls input n" << endl;
    cin >> n;
    cout << "Pls input m" << endl;
    cin >> m;

    float** array = new float* [n];

    for (int i = 0; i < n; ++i) {
    array = new float [m];
    }
    for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
    array[j] = sqrt(log(pow(i, 2) + pow(j, 2) + 2.5)) + 2 * (pow(i - 2.5, j));
    }
    }

    for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
    cout << array[j] << endl;
    }
    }


    float* vector = new float[n];
    for (int i = 0; i < n; ++i) {
    vector = (array[1] + array[i][/i][m - 1]) / 2.0;
    }


    cout << "Vector:" << endl;
    for (int i = 0; i < n; ++i) {
    cout << vector
    << " ";
    }
    cout << endl;

    float product = 1.0;
    for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
    if (array
    [j] < 10) {
    product *= array
    [j];
    }
    }
    }
    cout << "Low than 10 " << product << endl;



    for (int i = 0; i < n; ++i) {
    delete[] array[/I];
    }
    delete[] array;

    delete[] vector;


    return 0;
    }
     
Loading...
Top