Home Backend Development PHP Tutorial 数值分析(php兑现)一:Lagrange插值

数值分析(php兑现)一:Lagrange插值

Jun 13, 2016 am 11:01 AM
current dot gt this

数值分析(php实现)一:Lagrange插值
在学数值分析,试着用php实现下,有兴趣的朋友可以粘下来试试
Lagrange插值就是给出n个已知的点,用多项式函数拟合,求出拟合的函数,进而估算未知点函数值的一种插值过程
插值函数是f(x) = xigma(求和) lk*yk
本类实现了插值后显示函数图像的功能

<?php /* * Lagrange插值 * @wangbin * */class Lagrange{	private $dot = array();	public function __construct($array){        $this->dot = $array;    }    /*     * 计算lk     * */	private function get_lk($x,$k){        $num = count($this->dot['x']);		$omiga_xk = 1;		$omiga_x = 1;		for($i = 0;$i dot['x'][$k]-$this->dot['x'][$i]);				$omiga_x *= ($x - $this->dot['x'][$i]);			}		}		$lk = $omiga_x/$omiga_xk;		return $lk;	}	public function get_y($x){        $num = count($this->dot['x']);		$L = 0;		for($k = 0;$k get_lk($x,$k);            $L += ($this->dot['y'][$k]*$lk);		}		return $L;    }    public function draw(){        $img = imagecreate(500,500);        imagecolorallocate($img,255,255,2);        $num = count($this->dot['x']);        $max = 0;        for($i = 0;$i dot['x'][$i] ? $this->dot['x'][$i]:$max;        $r = 7;//点的半径        $step = 0.1;//步长        for($i = 0;$i dot['x'][$i],$this->dot['y'][$i],$r,$r,1);        }        for($i = $this->dot['x'][0]-10;$i get_y($current_x);            $next_x = $i + $step;            $next_y = $this->get_y($next_x);            imageline($img,$current_x,$current_y,$next_x,$next_y,1);        }        header("Content-type: image/png");        imagepng($img);        imagedestroy($img);    }}$x = new Lagrange(array('x'=>array(10,30,100,120,220),'y'=>array(20,40,240,220,340)));$x->draw();?>
Copy after login

1 楼 luozhong915127 2011-11-17  
数值分析(php兑现)一:Lagrange插值 全是代码,没有解释呀
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

DNS over TLS is now available for Windows 11 Insiders, here's how to enable it DNS over TLS is now available for Windows 11 Insiders, here's how to enable it Apr 16, 2023 pm 12:40 PM

Microsoft has launched build 25158 in the Windows 11 Development Channel and Windows Server 2022 Preview. For the former, this build includes a host of new features, including different search styles, notification badges in widgets, CD ripping in the media player, and more. Meanwhile, as usual, Windows Server 2022 doesn't even have an update log. Another feature briefly mentioned in Microsoft's announcement blog post is DNSoverTLS (DoT), a network enhancement now available to Insiders. If you are wondering what DoT is, it is DNSoverHT

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

What file is dot? What file is dot? Jun 17, 2021 pm 03:36 PM

DOT files are document template files in WORD. Read-only means that the system only reads the above data when it is running, and does not rewrite or change it. It is an attribute of the file. As long as the read-only file is not needed or used, it can be deleted.

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Let's talk about why Vue2 can access properties in various options through this Let's talk about why Vue2 can access properties in various options through this Dec 08, 2022 pm 08:22 PM

This article will help you interpret the vue source code and introduce why you can use this to access properties in various options in Vue2. I hope it will be helpful to everyone!

An article that understands this point and catches up with 70% of front-end people An article that understands this point and catches up with 70% of front-end people Sep 06, 2022 pm 05:03 PM

A colleague got stuck due to a bug pointed by this. Vue2’s this pointing problem caused an arrow function to be used, resulting in the inability to get the corresponding props. He didn't know it when I introduced it to him, and then I deliberately looked at the front-end communication group. So far, at least 70% of front-end programmers still don't understand it. Today I will share with you this link. If everything is wrong If you haven’t learned it yet, please give me a big mouth.

See all articles