Hi, need help figuring the problem in my code as it keeps saying Undefined operator '*' for input arguments of type 'inline'.

clear all; clc; close all; u=[2 0 1 5 1 7 4 3 3]; n=max(u); m=mean(u); syms x; f=inline((x-m)^n)*exp(-(-x - m)^2); gf=ezplot(f,[-2,8]); hold on grid on df=diff(f(x),1); xin=solve(f(x)); xint=[xin,zeros(length(xin),1)]; yin=[0,f(0)]; plot(xint(:,1),xint(:,2),'+'); plot(yin(:,1),yin(:,2),'+'); hold on crit=solve(df); critp=[crit,f(crit)]; plot(critp(:,1),critp(:,2),'+') hold on dff=diff(f(x),2); inf=solve(dff); infp=[inf,f(inf)]; plot(infp(:,1),infp(:,2),'+');

 Respuesta aceptada

First, you need to put the numeric assignments after the syms call in order for them to be used in the Symbolic Math Toolbox functions.
Second, you need to put single quotes around the expression in your inline function. However, you need to replace the inline function with an anonymous function. You need to learn about anonymous functions, because the inline function will disappear in the not distant future.
Your first 5 lines then need to be:
syms x
u=[2 0 1 5 1 7 4 3 3];
n=max(u);
m=mean(u);
f = @(x) ((x-m).^n).*exp(-(-x - m).^2);
These will work with the rest of your code.
This resolves the problem you posted. Your code has logic errors that only you can resolve.

2 comentarios

Thanks Star Strider for the answer!, I'm new to matlab so I'm having some problems but thanks anyway man!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Scope Variables and Generate Names en Centro de ayuda y File Exchange.

Preguntada:

el 8 de Mayo de 2017

Comentada:

el 8 de Mayo de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by