minimize the error between calculated values and experimental results

11 ビュー (過去 30 日間)
MEENAKSHI SHARMA
MEENAKSHI SHARMA 2020 年 4 月 12 日
コメント済み: MEENAKSHI SHARMA 2020 年 4 月 16 日
Hello, I am writing the following code to minimize the error between calculated values and experimental results:
K=[1 2 2.8 3.3 3.5 3.6]; %some data to test
v = sym('v',[1 2]);
a = v(1); b = v(2);
e=[1 2 3 4 5 6]
eo=2
for i=1:1:6
D(i)=@(v)a*(e(i)-eo)^b
E(i)=e(i)*(1-D(i));
R(i)=(K(i)-E(i))^2;
end
RM=0
for i=1:1:6
RM=RM+R(i)
end
RMS=(RM)^(1/2)
v = [0.12 2];
c=fminsearch(RMS,v)
Its showing error. Can you please help to solve the issue.

採用された回答

Guru Mohanty
Guru Mohanty 2020 年 4 月 15 日
Hi, I understand you are trying to minimize error for given set of data. The error in your code is due the fact that the function fminsearch takes function handle as input, instead of sym. First you need to convert the ‘RMS’ to function handle using matlabFunction and then compute the minimum. Here is the modified code for it.
clear all;
clc;
K=[1 2 2.8 3.3 3.5 3.6]; %some data to test
v = sym('v',[1 2]);
a = v(1); b = v(2);
e=[1 2 3 4 5 6];
eo=2;
RM=0;
for i=1:1:6
D(i)=a*(e(i)-eo)^b;
E(i)=e(i)*(1-D(i));
R(i)=(K(i)-E(i))^2;
RM=RM+R(i);
end
RMS=(RM)^(1/2);
RMS=matlabFunction(RMS,'Vars',{[v(1),v(2)]});
v = [0.12 2];
c = fminsearch(RMS, v);
disp(c);
  1 件のコメント
MEENAKSHI SHARMA
MEENAKSHI SHARMA 2020 年 4 月 16 日
@Guru Mohanty - Thanks a lot for your answer.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by