Error using inline/subsref (line 12) Not enough inputs to inline function.

Hi, I've been tested so many times and tried all the answers from here and still not working.
if the expression is
with
m=4.541*TN*S0/T
T=1:0.1:100
TN=70
S0=0.99
integration with simpson 1/3
here my code:
clear all; clc;
f1=inline('3/2*(cos(x)^2)*exp(m*(3/2*(cos(x)^2))-1/2)*sin(x)','m','x');
f2=inline('exp(m*(3/2*(cos(x)^2)-1/2))','m','x');
T0=1;
TM=100;
dT=0.1;
TN=70;
S0=0.99;
for T=T0:dT:TM;
m=4.541*TN*S0/T;
a=0;b=pi;
c=0;d=pi;
n=100;
h=(b-a)/n;
f1a=f1(a);f1b=f1(b);
f2a=f2(a);f2b=f2(b);
jumeven=0;jumodd=0;
for i=1:n-1
p=mod(1,2);
if p==0
xi=x+i*h;
jumeven=jumeven+f(xi);
else
xi=x+i*h;
jumodd=jumodd+f(xi);
end
end
I1=(h/3)*(f1a+4*jumodd+2*jumeven+f1b);
I2=(h/3)*(f2c+4*jumodd+2*jumeven+f2d);
S=I1/I2;
S0=S;
end
disp([S' T']);
disp([S]);
plot(S,T,'ob-','linewidth',3);
grid on;
xlabel('S','fontsize',18);
ylabel('T','fontsize',18);

4 Kommentare

What advantage do you see in using inline ? Have you benchmarked it for your situation and found it gives better performance? Have you found something using inline that you have not been able to express in other ways?
I ask because Mathworks has recommended against using inline() for roughly the last 18 years.
Humm sorry, I don't know any other way, and why is it inline? because, it's already in my lecturer's guide. And btw, any suggestion from you? I'm happy to try it
Stephen23
Stephen23 am 12 Mär. 2022
Bearbeitet: Stephen23 am 12 Mär. 2022
"it's already in my lecturer's guide."
Your lecturer wrote their (mis)guide back in the dark ages. You should ask for your money back.
"And btw, any suggestion from you? I'm happy to try it"
You do what the MATLAB documentation recommends:
f1 = @(m,x) 3/2*(cos(x).^2).*exp(m.*(3/2*(cos(x).^2))-1/2).*sin(x);
f2 = @(m,x) exp(m.*(3/2*(cos(x).^2)-1/2));

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

These lines:
f1a=f1(a);f1b=f1(b);
f2a=f2(a);f2b=f2(b);
Should be:
f1a=f1(m,a);f1b=f1(m,b);
f2a=f2(m,a);f2b=f2(m,b);
As the functions f1, f2 need two inputs.

5 Kommentare

another error appears: Unrecognized function or variable 'f'.
jumodd=jumodd+f(xi);
thanks before
It is because, there is no function with the name f. Either you have to define it or it could be a typo error for f1 or f2.
and 1 more, how can i define f as f1/f2?
okayy got it, thankyou so much @KSSV and @Walter Roberson 🙏

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Function Creation finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 11 Mär. 2022

Bearbeitet:

am 12 Mär. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by