Can't call my function to another m file
Mostrar comentarios más antiguos
I have two m files containing in one folder. I want to calculate error of exact and numerical solution on the third m file. The functions names are
T_exact=ExactSol(x,t,alpha,y);
T_num=NumericalSol(x,nj,r,t_end);
The code to the third file is given below:
alpha=10^-3;
T1=800;
T2=200;
nj=100;
T0=T1*ones(nj,1);
T0(nj/2+1:nj)=T2*ones(1,nj/2);
r=0.4;
t_end=50;
delta_x=1/nj;
x=([1+nj]-0.5)/nj;
T_num=NumericalSol(x,nj,r,t_end);
T_exact=ExactSol(x,t,alpha,y)
err=sqrt(delta_x*(T_num-T_exact)*(T_num-T_exact))
The Names of two m files are Assigment_2 and Assigment_1. I am recieving an error that T_num and T_exact are't defined. How to solve this problem?
7 comentarios
Rik
el 2 de Sept. de 2020
Where did you store the NumericalSol and ExactSol functions?
Muhammad Umar Khan
el 2 de Sept. de 2020
Rik
el 2 de Sept. de 2020
You didn't write the function on a piece of paper. In which file did you store the function? And where is that file located relative to you current folder?
The code Bjorn suggested ( which('ExactSol') ) should answer most of that question.
Muhammad Umar Khan
el 2 de Sept. de 2020
Editada: Rik
el 2 de Sept. de 2020
Rik
el 2 de Sept. de 2020
So those two functions are in Assignment_1.m?
I would suggest you go back to the previous lessons of your Matlab course to have a look again at the fundamentals. Another option is to do the Onramp course that is provided by Mathworks for free.
Muhammad Umar Khan
el 2 de Sept. de 2020
Rik
el 2 de Sept. de 2020
Please attach these two files to your question. You're treating them as functions in the code you posted, but it is unclear if you made them actual functions.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Search Path en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!