Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.?

423 visualizzazioni (ultimi 30 giorni)
The error 'Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.', is coming up for line 84. Can anyone see my issue? this is my line 84:
c(i+1) = c(i) - parError(c(i), m, g)/pardError(c(i), m, g))
i am writting an NR soultion, this is my NR soultion;
init_guess = 8;
c(1) = init_guess;
lim = 0.01;
rel_error = 1;
i = 1;
eVec = [1:20];
while ((c(i)-c(i+1))>0.01 & (i < 20))
c(i+1) = c(i) - parError(c(i), m, g)/pardError(c(i), m, g))
rel_error = abs((c(i+1)-c(i))/(c(i)))
numbers[c(i),parError(c(i), m, g)]
numbers2[pardError(c(i), m, g), c(i+1)-c(i)];
eVec(i)=rel_error;
i = i+1;
% Creates strings to be printed
str1=['At c = ', num2str(numbers2(1)), ', the error = ', num2str(numbers2(2))];
str2=['The gradient is ', num2str(numbers2(1)), ', the step is ', num2str(numbers2(2))];
disp(str);
disp(str2);
end
for the parError and pardError, these are the functions;
function error = parError( c, m, g)
error = ( (40*c) / (m*g) )-( 1-exp( (-10*c)/m ) );
end
function dError = pardError( c, m, g)
dError=(40/(m*g)) -(( 10*exp( (-10*c)/m ) )/m)
end

Risposta accettata

Guillaume
Guillaume il 25 Feb 2020
Modificato: Guillaume il 25 Feb 2020
As per the error message: check for mismatched delimiters
c(i+1) = c(i) - parError(c(i), m, g)/pardError(c(i), m, g))
I count one more ) than there are (.
---
Notes:
  • I would recommend you don't use error as a variable name. It's already the name of an important matlab function.
  • These lines:
numbers[c(i),parError(c(i), m, g)]
numbers2[pardError(c(i), m, g), c(i+1)-c(i)];
are not valid syntax either.
  • I would replace:
str1=['At c = ', num2str(numbers2(1)), ', the error = ', num2str(numbers2(2))];
str2=['The gradient is ', num2str(numbers2(1)), ', the step is ', num2str(numbers2(2))];
by
str1 = sprintf('At c = %g, the error = %g', numbers2);
str2 = sprintf('The gradient is %g, the step is %g', numbers2)
  • it is puzzling that numbers2 used in both str1 and str2 contains c and the error and the gradient and the step.
  3 Commenti
Michelle Gaughan
Michelle Gaughan il 25 Feb 2020
numbers[c(i),parError(c(i), m, g)]
numbers2[pardError(c(i), m, g), c(i+1)-c(i)];
for these part not being valid syntax, what could i reply them with?
Guillaume
Guillaume il 25 Feb 2020
Modificato: Guillaume il 25 Feb 2020
I'm not sure what the two lines are meant to do. Perhaps you're trying to assign a 2 element vector to each variable in which case you're missing a =
numbers = [c(i),parError(c(i), m, g)];
numbers2 = [pardError(c(i), m, g), c(i+1)-c(i)];
maybe?

Accedi per commentare.

Più risposte (3)

Tshiabu Angelus Dan
Tshiabu Angelus Dan il 3 Mag 2023
  2 Commenti
Steven Lord
Steven Lord il 3 Mag 2023
It's easier to comment on code if you post it as text rather than an image. Please post your code as text in future questions.
Anyway, you're missing the multiplication symbols in two places. Where you have (2/Ts)(1-z) you need * between those terms, (2/Ts)*(1-z). I think if you move the cursor over one of those inner parentheses on that line the Editor will indicate one of those parentheses in each of those terms are in columns 17 and 33 as stated in the error messages.

Accedi per commentare.


Tshiabu Angelus Dan
Tshiabu Angelus Dan il 5 Mag 2023
import numpy as np
import matplotlib.pyplot as plt
define input signal x
x = np.sin(np.arange(0, 2*np.pi, 0.1));
calculate output signal y using digital differentiator
y = np.append*(x[0], np.diff(x))
plot input and output signals
plt.plot(x, label='input signal')
plt.plot(y, label='output signal')
plt.legend()
plt.xlabel('Sample number')
plt.ylabel('Amplitude')
plt.title('Digital Differentiator Output for a Sinusoidal Signal')
plt.show()
QUESTION1_5a
File: QUESTION1_5a.m Line: 8 Column: 16
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
QUESTION1_5a
File: QUESTION1_5a.m Line: 8 Column: 16
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
QUESTION1_5a
File: QUESTION1_5a.m Line: 8 Column: 17
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
  2 Commenti
Steven Lord
Steven Lord il 5 Mag 2023
The * between the name of the function (np.append) and the parentheses containing its input arguments looks suspicious.
Walter Roberson
Walter Roberson il 16 Mag 2023
import numpy as np
In MATLAB, import does not accept an as clause.
define input signal x
There is no supplied MATLAB function named define -- but it is potentially possible to define a function with the name define that accepted multiple character vectors as parameters, so this is potentially a valid MATLAB statement.
calculate output signal y using digital differentiator
Same remarks as for define
y = np.append*(x[0], np.diff(x))
In MATLAB, [] cannot appear directly after a name. [] is used for list building (but not for indexing). A constructed list would need to have an operator between any previous part of the expression and the list.

Accedi per commentare.


Tshiabu Angelus Dan
Tshiabu Angelus Dan il 16 Mag 2023
Modificato: Walter Roberson il 16 Mag 2023
Gp = 10^(-2/20); Gs = 10^(-12/20); wp1 = 120/(2*pi); wp2 = 300/(2*pi); ws1 = 45/(2*pi); ws2 = 450/(2*pi);
% Pre-warping Ts = 1/500; % choose highest sampling period Wp1 = tan(wp1*pi*Ts); Wp2 = tan(wp2*pi*Ts); Ws1 = tan(ws1*pi*Ts); Ws2 = tan(ws2*pi*Ts);
% Analog filter design Rp = -20*log10(Gp); Rs = -20*log10(Gs); [n, Wn] = cheb2ord([Wp1 Wp2], [Ws1 Ws2], Rp, Rs); [b, a] = cheby2(n, Rs, [Ws1 Ws2]);
% Digital filter design using bilinear transformation [bd, ad] = bilinear(b, a, 1/Ts);
% Filter the input signal using the designed filter t = 0:Ts:1; x = 1 + sin(10*pi*t) + sin(200*pi*t) + sin(400*pi*t); y = filter(bd, ad, x);
% Plot the input and output signals subplot(2,1,1) plot(t, x) title('Input Signal') xlabel('Time (s)') ylabel('Amplitude')
subplot(2,1,2) plot(t, y) title('Filtered Signal') xlabel('Time (s)') ylabel('Amplitude')
From this Design and code how can I plot the frequency response for Lowpass Chebyshev and Bandstop Chebyshev for Lowpass, Highpass Chebyshev and Bandpass Chebyshev for Highpass.
  1 Commento
Walter Roberson
Walter Roberson il 16 Mag 2023
This does not appear to be an explanation of why you can get the "invalid expression" message. It does not appear to fit within the context of the current discussion.

Accedi per commentare.

Categorie

Scopri di più su Audio Processing Algorithm Design in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by