C++ 中的 norm() 函式及其示例


在本文中,我們將討論 C++ STL 中 norm() 函式的工作原理、語法以及示例。

什麼是 norm()?

norm() 函式是 C++ STL 中的一個內建函式,它定義在 <complex> 標頭檔案中。norm() 函式用於獲取複數的範數。

複數的範數是一個數的平方幅度。因此,簡單來說,該函式會查詢一個複數(包括其虛數和實數)的平方幅度。

語法

double norm(ArithmeticType num);

引數

該函式接受以下引數:

  • num ― 我們要對其進行處理的複數值。

返回值

此函式返回 num 的範數值。

示例

輸入

complex<double> comp_num(6.9, 2.6);
norm(comp_num);

輸出

The value of norm of (6.9,2.6) is 54.37

示例

 線上演示

#include <bits/stdc++.h>
using namespace std;
int main (){
   complex<double> comp_num(6.9, 2.6);
   cout<<"The value of norm of " << comp_num<< " is ";
   cout << norm(comp_num) << endl;
   return 0;
}

輸出

The value of norm of (6.9,2.6) is 54.37

示例

 線上演示

#include <bits/stdc++.h>
using namespace std;
int main (){
   complex<double> comp_num(2.4, 1.9);
   cout<<"The value of norm of " << comp_num<< " is ";
   cout << norm(comp_num) << endl;
   return 0;
}

示例

The value of norm of (2.4,1.9) is 9.37

更新日期:2020 年 4 月 17 日

1K+ 瀏覽

啟動您的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.