Info

This question is closed. Reopen it to edit or answer.

If any one can remove the error from this code.when i run this code it is showing the following error

1 view (last 30 days)
u_xt = @(x,t,a,b) exp(a*t+b*x); % Create a function handle
x=[0:0.1:1]; %NOTE: I chose the step-size here as 0.1
t=[0:0.1:1]; %NOTE: Since your boundary conditions for x and t are identical [0 1] the step size has to be same for both
a = 5; % (say)
b = 2; % (say)
result = u_xt(x,t,a,b);
plot(u_xt,x);
% If you want to plot both on the same figure
%hold on;
%plot(u_xt,t);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Error using plot
Conversion to double from function_handle is not possible.
.
Error in ROUGH (line 7)
plot(u_xt,x);

Answers (1)

Roger Stafford
Roger Stafford on 14 Feb 2016
As the error message indicates, you are erroneously using a function handle, namely 'u_xt', as though it were an array that could be plotted. This you cannot do. In place of 'u_xt' in the 'plot' functions you should have 'result' - it is a true array and 'plot' would accept it:
plot(result,x)

This question is closed.

Community Treasure Hunt

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

Start Hunting!