matlab - I'm getting an error "Undefined function 'Romberg' for input arguments of type 'char'." I'm trying to code the romberg integration method
问题描述
I'm trying to code the romberg integration method on matlab. I think I coded it right but I'm not getting why I have this error.
This is the function.
function[t , r] = Romberg (fun, a, b, nmax)
f = inline(fun);
r(1, 1) = (b - a) * (f(a) + f(b)) / 2;
for i = 1 : nmax
h(i) = (b-a) /2^(i) ;
m = 0;
for k = 1 : (2^(i))-1
m = m + f (a+k*h(i));
end
r(i + 1, 1) = (h(i) / 2) * (f(a) + f(b) + 2*m);
for j = 2 : i
r(i, j) = r(i, j-1) + (r(i, j-1) - r(i - 1, j - 1)) / (4^(j-1) - 1);
end
end
t = r (i, j)
This is its call
clc; clear all; close all;
a = 0;
b = pi;
nmax = 3;
fun ='sin (x)' ;
[t, r]= Romberg (fun, a, b, nmax)
And this is the error: Undefined function 'Romberg' for input arguments of type 'char'.
解决方案
推荐阅读
- debugging - 调试节点时变量的空对象
- perl - Perl: LWP::UserAgent 关于传递参数的规则
- java - 无法使用 Jackson 反序列化 Object 值(没有基于委托或基于属性的 Creator)
- html - 使用 HTML 和 Css 创建交互式半圆导航
- laravel - Laravel 5.5 项目下载文件安装在浏览器中打开它们 PHP 7.1 MAC
- node.js - 无法在节点 js REST API 中使用猫鼬保存超过 2 个属性
- javascript - 在 onchange 事件上添加变量值
- python - 如何在python docx中垂直写表
- c++ - 学习openCV,获取LNK2019(未解析的外部符号)
- kubernetes - 部署 YAML 文件时出现 Kubernetes 错误