フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

mex-file creation

1 回表示 (過去 30 日間)
dario cecchetti
dario cecchetti 2017 年 11 月 13 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I was trying to create a mex-file, however I can't do it beacuse Matlab shows the following error: Class function_handle is not support by coder Type. I wrote the following script and functions to calculate the solution of non-linear equation.
clear
clc
ep=10^(-6); % tollerance
itermax=50; % number max of iterations
a=0; % a,b initial interval
b=2;
[x,iter] = Bisection(@f,a,b,ep,itermax)
%%%functions
function [x,iter] = Bisection(f,a,b,ep,itermax)
%
% Function for the solution of the non-linear equation
% f(x)=0
% by the BISECTION method
%
% INPUT data:
% f name of the MATLAB function implementing
% the non-linear function
%
% a,b initial interval [a,b]
% such that f(a)f(b) < 0
%
% ep tolerance (>0)
%
% OUTPUT data:
% x solution of the non-linear equation
% iter number of performed iterations
%
fa = feval(f,a);
fb = feval(f,b);
if fa*fb > 0
fprintf('\n\nThe initial interval does not satisfy f(a)f(b) < 0.')
return
end
iter=0;
% while abs(a-b) > ep+eps*max(abs(a),abs(b))
while abs(a-b) >= 2*ep && (iter < itermax)
mid = (a+b)/2;
fmid = feval(f,mid);
if fa*fmid<=0
% root in [a,mid].
b = mid;
fb = fmid;
else
% root in [mid,b].
a = mid;
fa = fmid;
end
iter=iter+1;
end
x = (a+b)/2;
function [ y ] = f( x )
y=x.^2-1;
end
  1 件のコメント
Jan
Jan 2017 年 11 月 13 日
You forgot to mention, when the error occurs. Do I understand correctly, that the shown code works reliable in Matlab and it fails only, if you try to compile it? Then please explain, if compiling is really needed.

回答 (1 件)

Jan
Jan 2017 年 11 月 13 日
編集済み: Jan 2017 年 11 月 13 日
  3 件のコメント
Jan
Jan 2017 年 11 月 13 日
Did you read my answer?
dario cecchetti
dario cecchetti 2017 年 11 月 13 日
of course, I answered at your following answer "You forgot to mention, when the error occurs. Do I understand correctly, that the shown code works reliable in Matlab and it fails only, if you try to compile it? Then please explain, if compiling is really needed." Then I checked your second answer and I couldn't to solve it. I'm sorry but my english it's not very good.

この質問は閉じられています。

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by