MATLAB Answers

Error in using Inline function and fzero

Hello, Can anybody help me? I want to figure out where I am doing a mistake in program. The only variable is X and Cp is an input.

Cp                          = double(zeros(49792,1));
P                           = size(x.Time_Series);
Q                           = P(1,1);
Cp(1,1)= 0.126826003999670;
Cp(2,1)= 0.325943036562508;
for k=3:Q;
    hx = inline( '12.175*(X - 2*Cp(k-1,1) + Cp(k-2,1)) + 13.525*((X - Cp(k-1,1))* abs(X - Cp(k-1,1))) + X - SINGLE_FINAL_TIME_SERIES_OF_TAPS_NEAR_DOMINANT_OPENING(k,1)','X',Cp);
    Cp(k) = hp(1);
I am getting this error
Error: The expression to the left of the equals sign is not a valid target for an

If in inline function, I remove Cp which is given after X (at the very last near the bracket), then it shows error: too many inputs to inline function. Pls help. thanks.


Log in to comment.


No products are associated with this question.

2 Answers

Answer by Star Strider
on 20 Mar 2014
 Accepted Answer


Unlike anonymous functions that use workspace variables, inline functions ignore anything that isn’t in their argument list. It has no idea what SINGLE_FINAL_TIME_SERIES_OF_TAPS_NEAR_DOMINANT_OPENING(k,1) or k are.

Also, fzero only accepts single-variable functions.


Eureka! It does produce the results very fast. Unbelievably in 163 seconds for all 49792 values. Thanks a lot for this. I want to explain you what I am trying to achieve here although it may not be relevant to your field. Cp means pressure coefficient. Pr. coefficients are measured in a boundary layer wind tunnel at frequency of 500 Hz for 100 s. That is why there are 50000 values approx represented by SFTSOTNDO. The values measured were external Cp and I wanted to derive internal Cp using the equation above. There is no need of plot between these two. However, the values I have got are relatively higher. They should all be less than 3 or 4. But leaving that, it is major work done for me. Thanks a lot again. I have named this program Star_Strider as a tribute and a sign of respect.

My pleasure!

Wow! And a tribute, too! Thank you!

I have a background in physical chemistry and am an instrument-rated private pilot, so I'm slightly familiar with what you are doing. I do not have sufficient background in fluid dynamics to understand it in any detail, though.

Thanks for helping and telling about your background. Take care.

Log in to comment.

Answer by Sean de Wolski
on 20 Mar 2014

Avoid using inline, instead use an anonymous function


Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!