Error while evaluating the function convolution





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















This is my first attempt to write anything in matlab, so please, be patient.



I am trying to evaluate the solution of the following ODE: w'' + N(w, w') = f(t) with the Cauchy conditions w(0) = w'(0) = 0. Here N is a given nonlinear function, f is a given source. I also need the function



enter image description here



where G is the solution of the following ODE:



enter image description here



where G(0) = G'(0) =0, s is a constant, and



enter image description here



My try is as follows: I define N, f, w and G:



k = 1000;
N = @(g1,g2) g1^2 + sin(g2);
f = @(t) 0.5 * (1 + tanh(k * t));

t = linspace(0, 10, 100);
w = nonlinearnonhom(N, f);
G = nonlinearGreen(N);


This part is ok. I can plot both w and G: both seems to be correct. Now, I want to evaluate wG. For that purpose, I use the direct and inverse Laplace transforms as follows:



wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


but is says



Undefined function 'laplace' for input arguments of type 'double'.

Error in main (line 13)
wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


Now, I am not sure if this definition of wG is correct at all and if there are not any other definitions.



Appendix: nonlinearGreen(N) is defined as follows:



function G = nonlinearGreen(N)

eps = .0001;
del = @(t)[1/(eps * pi) * exp( -t^2/eps^2)];

eqGreen = @(t, g)[g(2); - N(g(1),g(2)) + del(t)];
tspan = [0, 100];
Cc = [0, 0];
solGreen = ode45(eqGreen, tspan, Cc);
t = linspace(0, 10, 1000);
G = deval(solGreen, t, 1);

end


and nonlinearnonhom is defined as follows:



function w = nonlinearnonhom(N, f)

eqnonhom = @(t, g)[g(2); - N(g(1),g(2)) + f(t)];
tspan = [0, 100];
Cc = [0, 0];
solnonhom = ode45(eqnonhom, tspan, Cc);
t = linspace(0, 10, 100);
w = deval(solnonhom, t, 1);

end









share|improve this question

























  • Hi, please maintain the question with minimal code, if you change some parts, remove the old ones. If it's not about convolution anymore, update the title of your question. Also, include the whole error message of matlab (the line numbers). But I suspect that you try to index an array with a symbol which is forbidden.

    – Bebs
    Nov 30 '18 at 8:05













  • Thank you for your guidance. I left only the codes for evaluating G and w just in case if someone wants to run the whole program.

    – Asatur Khurshudyan
    Nov 30 '18 at 10:48











  • I want to plot w and wG fot 0 < t < 10.

    – Asatur Khurshudyan
    Nov 30 '18 at 12:04






  • 1





    You seem to have a lot of problems in one. You need to apply the Divide and Conquer strategy and split your problem in different smaller problems easier to solve.

    – Bebs
    Nov 30 '18 at 12:16


















2















This is my first attempt to write anything in matlab, so please, be patient.



I am trying to evaluate the solution of the following ODE: w'' + N(w, w') = f(t) with the Cauchy conditions w(0) = w'(0) = 0. Here N is a given nonlinear function, f is a given source. I also need the function



enter image description here



where G is the solution of the following ODE:



enter image description here



where G(0) = G'(0) =0, s is a constant, and



enter image description here



My try is as follows: I define N, f, w and G:



k = 1000;
N = @(g1,g2) g1^2 + sin(g2);
f = @(t) 0.5 * (1 + tanh(k * t));

t = linspace(0, 10, 100);
w = nonlinearnonhom(N, f);
G = nonlinearGreen(N);


This part is ok. I can plot both w and G: both seems to be correct. Now, I want to evaluate wG. For that purpose, I use the direct and inverse Laplace transforms as follows:



wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


but is says



Undefined function 'laplace' for input arguments of type 'double'.

Error in main (line 13)
wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


Now, I am not sure if this definition of wG is correct at all and if there are not any other definitions.



Appendix: nonlinearGreen(N) is defined as follows:



function G = nonlinearGreen(N)

eps = .0001;
del = @(t)[1/(eps * pi) * exp( -t^2/eps^2)];

eqGreen = @(t, g)[g(2); - N(g(1),g(2)) + del(t)];
tspan = [0, 100];
Cc = [0, 0];
solGreen = ode45(eqGreen, tspan, Cc);
t = linspace(0, 10, 1000);
G = deval(solGreen, t, 1);

end


and nonlinearnonhom is defined as follows:



function w = nonlinearnonhom(N, f)

eqnonhom = @(t, g)[g(2); - N(g(1),g(2)) + f(t)];
tspan = [0, 100];
Cc = [0, 0];
solnonhom = ode45(eqnonhom, tspan, Cc);
t = linspace(0, 10, 100);
w = deval(solnonhom, t, 1);

end









share|improve this question

























  • Hi, please maintain the question with minimal code, if you change some parts, remove the old ones. If it's not about convolution anymore, update the title of your question. Also, include the whole error message of matlab (the line numbers). But I suspect that you try to index an array with a symbol which is forbidden.

    – Bebs
    Nov 30 '18 at 8:05













  • Thank you for your guidance. I left only the codes for evaluating G and w just in case if someone wants to run the whole program.

    – Asatur Khurshudyan
    Nov 30 '18 at 10:48











  • I want to plot w and wG fot 0 < t < 10.

    – Asatur Khurshudyan
    Nov 30 '18 at 12:04






  • 1





    You seem to have a lot of problems in one. You need to apply the Divide and Conquer strategy and split your problem in different smaller problems easier to solve.

    – Bebs
    Nov 30 '18 at 12:16














2












2








2








This is my first attempt to write anything in matlab, so please, be patient.



I am trying to evaluate the solution of the following ODE: w'' + N(w, w') = f(t) with the Cauchy conditions w(0) = w'(0) = 0. Here N is a given nonlinear function, f is a given source. I also need the function



enter image description here



where G is the solution of the following ODE:



enter image description here



where G(0) = G'(0) =0, s is a constant, and



enter image description here



My try is as follows: I define N, f, w and G:



k = 1000;
N = @(g1,g2) g1^2 + sin(g2);
f = @(t) 0.5 * (1 + tanh(k * t));

t = linspace(0, 10, 100);
w = nonlinearnonhom(N, f);
G = nonlinearGreen(N);


This part is ok. I can plot both w and G: both seems to be correct. Now, I want to evaluate wG. For that purpose, I use the direct and inverse Laplace transforms as follows:



wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


but is says



Undefined function 'laplace' for input arguments of type 'double'.

Error in main (line 13)
wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


Now, I am not sure if this definition of wG is correct at all and if there are not any other definitions.



Appendix: nonlinearGreen(N) is defined as follows:



function G = nonlinearGreen(N)

eps = .0001;
del = @(t)[1/(eps * pi) * exp( -t^2/eps^2)];

eqGreen = @(t, g)[g(2); - N(g(1),g(2)) + del(t)];
tspan = [0, 100];
Cc = [0, 0];
solGreen = ode45(eqGreen, tspan, Cc);
t = linspace(0, 10, 1000);
G = deval(solGreen, t, 1);

end


and nonlinearnonhom is defined as follows:



function w = nonlinearnonhom(N, f)

eqnonhom = @(t, g)[g(2); - N(g(1),g(2)) + f(t)];
tspan = [0, 100];
Cc = [0, 0];
solnonhom = ode45(eqnonhom, tspan, Cc);
t = linspace(0, 10, 100);
w = deval(solnonhom, t, 1);

end









share|improve this question
















This is my first attempt to write anything in matlab, so please, be patient.



I am trying to evaluate the solution of the following ODE: w'' + N(w, w') = f(t) with the Cauchy conditions w(0) = w'(0) = 0. Here N is a given nonlinear function, f is a given source. I also need the function



enter image description here



where G is the solution of the following ODE:



enter image description here



where G(0) = G'(0) =0, s is a constant, and



enter image description here



My try is as follows: I define N, f, w and G:



k = 1000;
N = @(g1,g2) g1^2 + sin(g2);
f = @(t) 0.5 * (1 + tanh(k * t));

t = linspace(0, 10, 100);
w = nonlinearnonhom(N, f);
G = nonlinearGreen(N);


This part is ok. I can plot both w and G: both seems to be correct. Now, I want to evaluate wG. For that purpose, I use the direct and inverse Laplace transforms as follows:



wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


but is says



Undefined function 'laplace' for input arguments of type 'double'.

Error in main (line 13)
wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


Now, I am not sure if this definition of wG is correct at all and if there are not any other definitions.



Appendix: nonlinearGreen(N) is defined as follows:



function G = nonlinearGreen(N)

eps = .0001;
del = @(t)[1/(eps * pi) * exp( -t^2/eps^2)];

eqGreen = @(t, g)[g(2); - N(g(1),g(2)) + del(t)];
tspan = [0, 100];
Cc = [0, 0];
solGreen = ode45(eqGreen, tspan, Cc);
t = linspace(0, 10, 1000);
G = deval(solGreen, t, 1);

end


and nonlinearnonhom is defined as follows:



function w = nonlinearnonhom(N, f)

eqnonhom = @(t, g)[g(2); - N(g(1),g(2)) + f(t)];
tspan = [0, 100];
Cc = [0, 0];
solnonhom = ode45(eqnonhom, tspan, Cc);
t = linspace(0, 10, 100);
w = deval(solnonhom, t, 1);

end






matlab symbolic-math






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 30 '18 at 12:04









Bebs

1,27331424




1,27331424










asked Nov 29 '18 at 1:29









Asatur KhurshudyanAsatur Khurshudyan

1157




1157













  • Hi, please maintain the question with minimal code, if you change some parts, remove the old ones. If it's not about convolution anymore, update the title of your question. Also, include the whole error message of matlab (the line numbers). But I suspect that you try to index an array with a symbol which is forbidden.

    – Bebs
    Nov 30 '18 at 8:05













  • Thank you for your guidance. I left only the codes for evaluating G and w just in case if someone wants to run the whole program.

    – Asatur Khurshudyan
    Nov 30 '18 at 10:48











  • I want to plot w and wG fot 0 < t < 10.

    – Asatur Khurshudyan
    Nov 30 '18 at 12:04






  • 1





    You seem to have a lot of problems in one. You need to apply the Divide and Conquer strategy and split your problem in different smaller problems easier to solve.

    – Bebs
    Nov 30 '18 at 12:16



















  • Hi, please maintain the question with minimal code, if you change some parts, remove the old ones. If it's not about convolution anymore, update the title of your question. Also, include the whole error message of matlab (the line numbers). But I suspect that you try to index an array with a symbol which is forbidden.

    – Bebs
    Nov 30 '18 at 8:05













  • Thank you for your guidance. I left only the codes for evaluating G and w just in case if someone wants to run the whole program.

    – Asatur Khurshudyan
    Nov 30 '18 at 10:48











  • I want to plot w and wG fot 0 < t < 10.

    – Asatur Khurshudyan
    Nov 30 '18 at 12:04






  • 1





    You seem to have a lot of problems in one. You need to apply the Divide and Conquer strategy and split your problem in different smaller problems easier to solve.

    – Bebs
    Nov 30 '18 at 12:16

















Hi, please maintain the question with minimal code, if you change some parts, remove the old ones. If it's not about convolution anymore, update the title of your question. Also, include the whole error message of matlab (the line numbers). But I suspect that you try to index an array with a symbol which is forbidden.

– Bebs
Nov 30 '18 at 8:05







Hi, please maintain the question with minimal code, if you change some parts, remove the old ones. If it's not about convolution anymore, update the title of your question. Also, include the whole error message of matlab (the line numbers). But I suspect that you try to index an array with a symbol which is forbidden.

– Bebs
Nov 30 '18 at 8:05















Thank you for your guidance. I left only the codes for evaluating G and w just in case if someone wants to run the whole program.

– Asatur Khurshudyan
Nov 30 '18 at 10:48





Thank you for your guidance. I left only the codes for evaluating G and w just in case if someone wants to run the whole program.

– Asatur Khurshudyan
Nov 30 '18 at 10:48













I want to plot w and wG fot 0 < t < 10.

– Asatur Khurshudyan
Nov 30 '18 at 12:04





I want to plot w and wG fot 0 < t < 10.

– Asatur Khurshudyan
Nov 30 '18 at 12:04




1




1





You seem to have a lot of problems in one. You need to apply the Divide and Conquer strategy and split your problem in different smaller problems easier to solve.

– Bebs
Nov 30 '18 at 12:16





You seem to have a lot of problems in one. You need to apply the Divide and Conquer strategy and split your problem in different smaller problems easier to solve.

– Bebs
Nov 30 '18 at 12:16












1 Answer
1






active

oldest

votes


















2














You keep mixing different kind of types and it's not a good idea. I suggest you keep with symbolic all the way if you want to use the laplace function. When you define N and f with @(arobase) as function handles and not symbolic expressions as you might want to do. I suggest you have a look at symbolic documentation and rewrite your functions as symbolic.



Then, the error message is pretty clear.




Undefined function 'laplace' for input arguments of type 'double'.

Error in main (line 13)

wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);




It means that the function laplace can't have arguments of type double.



The problem is that your t is a vector of double. Another mistake is that s is not defined in your code.



According to Matlab documentation of laplace, all arguments are of type symbolic.



You can try to manually specify symbolic s and t.



% t = linspace(0, 10, 100); % This is wrong
syms s t
wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


I have no error after that.






share|improve this answer
























  • Thank you for your clarifications. I now want to plot w and wG on the same figure. I guess, I need to use fplot(@(t) wG, [0 10]), but it does not work.

    – Asatur Khurshudyan
    Nov 30 '18 at 12:09











  • This should be another question I guess...

    – Bebs
    Nov 30 '18 at 12:10











  • It's because the code needs significant change for plotting or I have chosen a wrong section for this question?

    – Asatur Khurshudyan
    Nov 30 '18 at 12:16












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53530572%2ferror-while-evaluating-the-function-convolution%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You keep mixing different kind of types and it's not a good idea. I suggest you keep with symbolic all the way if you want to use the laplace function. When you define N and f with @(arobase) as function handles and not symbolic expressions as you might want to do. I suggest you have a look at symbolic documentation and rewrite your functions as symbolic.



Then, the error message is pretty clear.




Undefined function 'laplace' for input arguments of type 'double'.

Error in main (line 13)

wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);




It means that the function laplace can't have arguments of type double.



The problem is that your t is a vector of double. Another mistake is that s is not defined in your code.



According to Matlab documentation of laplace, all arguments are of type symbolic.



You can try to manually specify symbolic s and t.



% t = linspace(0, 10, 100); % This is wrong
syms s t
wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


I have no error after that.






share|improve this answer
























  • Thank you for your clarifications. I now want to plot w and wG on the same figure. I guess, I need to use fplot(@(t) wG, [0 10]), but it does not work.

    – Asatur Khurshudyan
    Nov 30 '18 at 12:09











  • This should be another question I guess...

    – Bebs
    Nov 30 '18 at 12:10











  • It's because the code needs significant change for plotting or I have chosen a wrong section for this question?

    – Asatur Khurshudyan
    Nov 30 '18 at 12:16
















2














You keep mixing different kind of types and it's not a good idea. I suggest you keep with symbolic all the way if you want to use the laplace function. When you define N and f with @(arobase) as function handles and not symbolic expressions as you might want to do. I suggest you have a look at symbolic documentation and rewrite your functions as symbolic.



Then, the error message is pretty clear.




Undefined function 'laplace' for input arguments of type 'double'.

Error in main (line 13)

wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);




It means that the function laplace can't have arguments of type double.



The problem is that your t is a vector of double. Another mistake is that s is not defined in your code.



According to Matlab documentation of laplace, all arguments are of type symbolic.



You can try to manually specify symbolic s and t.



% t = linspace(0, 10, 100); % This is wrong
syms s t
wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


I have no error after that.






share|improve this answer
























  • Thank you for your clarifications. I now want to plot w and wG on the same figure. I guess, I need to use fplot(@(t) wG, [0 10]), but it does not work.

    – Asatur Khurshudyan
    Nov 30 '18 at 12:09











  • This should be another question I guess...

    – Bebs
    Nov 30 '18 at 12:10











  • It's because the code needs significant change for plotting or I have chosen a wrong section for this question?

    – Asatur Khurshudyan
    Nov 30 '18 at 12:16














2












2








2







You keep mixing different kind of types and it's not a good idea. I suggest you keep with symbolic all the way if you want to use the laplace function. When you define N and f with @(arobase) as function handles and not symbolic expressions as you might want to do. I suggest you have a look at symbolic documentation and rewrite your functions as symbolic.



Then, the error message is pretty clear.




Undefined function 'laplace' for input arguments of type 'double'.

Error in main (line 13)

wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);




It means that the function laplace can't have arguments of type double.



The problem is that your t is a vector of double. Another mistake is that s is not defined in your code.



According to Matlab documentation of laplace, all arguments are of type symbolic.



You can try to manually specify symbolic s and t.



% t = linspace(0, 10, 100); % This is wrong
syms s t
wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


I have no error after that.






share|improve this answer













You keep mixing different kind of types and it's not a good idea. I suggest you keep with symbolic all the way if you want to use the laplace function. When you define N and f with @(arobase) as function handles and not symbolic expressions as you might want to do. I suggest you have a look at symbolic documentation and rewrite your functions as symbolic.



Then, the error message is pretty clear.




Undefined function 'laplace' for input arguments of type 'double'.

Error in main (line 13)

wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);




It means that the function laplace can't have arguments of type double.



The problem is that your t is a vector of double. Another mistake is that s is not defined in your code.



According to Matlab documentation of laplace, all arguments are of type symbolic.



You can try to manually specify symbolic s and t.



% t = linspace(0, 10, 100); % This is wrong
syms s t
wG = ilaplace(laplace(G, t, s) * laplace(f, t, s), s, t);


I have no error after that.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 30 '18 at 11:27









BebsBebs

1,27331424




1,27331424













  • Thank you for your clarifications. I now want to plot w and wG on the same figure. I guess, I need to use fplot(@(t) wG, [0 10]), but it does not work.

    – Asatur Khurshudyan
    Nov 30 '18 at 12:09











  • This should be another question I guess...

    – Bebs
    Nov 30 '18 at 12:10











  • It's because the code needs significant change for plotting or I have chosen a wrong section for this question?

    – Asatur Khurshudyan
    Nov 30 '18 at 12:16



















  • Thank you for your clarifications. I now want to plot w and wG on the same figure. I guess, I need to use fplot(@(t) wG, [0 10]), but it does not work.

    – Asatur Khurshudyan
    Nov 30 '18 at 12:09











  • This should be another question I guess...

    – Bebs
    Nov 30 '18 at 12:10











  • It's because the code needs significant change for plotting or I have chosen a wrong section for this question?

    – Asatur Khurshudyan
    Nov 30 '18 at 12:16

















Thank you for your clarifications. I now want to plot w and wG on the same figure. I guess, I need to use fplot(@(t) wG, [0 10]), but it does not work.

– Asatur Khurshudyan
Nov 30 '18 at 12:09





Thank you for your clarifications. I now want to plot w and wG on the same figure. I guess, I need to use fplot(@(t) wG, [0 10]), but it does not work.

– Asatur Khurshudyan
Nov 30 '18 at 12:09













This should be another question I guess...

– Bebs
Nov 30 '18 at 12:10





This should be another question I guess...

– Bebs
Nov 30 '18 at 12:10













It's because the code needs significant change for plotting or I have chosen a wrong section for this question?

– Asatur Khurshudyan
Nov 30 '18 at 12:16





It's because the code needs significant change for plotting or I have chosen a wrong section for this question?

– Asatur Khurshudyan
Nov 30 '18 at 12:16




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53530572%2ferror-while-evaluating-the-function-convolution%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)