Azzera filtri
Azzera filtri

Incorrect dimensions for matrix multiplication

5 visualizzazioni (ultimi 30 giorni)
clear all; close all;
% param value
k0 = 0.244; p=536.2; q=0.0000376;
% the function
k = @(t,u) (k0 + (p*k0.^u-q*k0)*t +(p*k0.^u-q*k0).*(p*u*k0.^u-q)*t.^2/factorial(2)...
+(p*k0.^u-q*k0).*((p*u*k0.^u-q).^2-p*u*(u-1)*k0.^(u-1)./2)*t.^3/factorial(3));
% grid
t = linspace(0,0.1);
u = linspace(0.3,0.9);
[T,U] = meshgrid(t,q);
% evaluate function
Z = k(T,U);
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication.

Error in solution>@(t,u)(k0+(p*k0.^u-q*k0)*t+(p*k0.^u-q*k0).*(p*u*k0.^u-q)*t.^2/factorial(2)+(p*k0.^u-q*k0).*((p*u*k0.^u-q).^2-p*u*(u-1)*k0.^(u-1)./2)*t.^3/factorial(3)) (line 5)
k = @(t,u) (k0 + (p*k0.^u-q*k0)*t +(p*k0.^u-q*k0).*(p*u*k0.^u-q)*t.^2/factorial(2)...
% plot
figure
surf(T,U,Z)
%surf(T,Q,Z,'facecolor','none')

Risposta accettata

VBBV
VBBV il 31 Mag 2024
Modificato: VBBV il 31 Mag 2024
k = @(t,u) (k0 + (p*k0.^u-q*k0).*t +(p*k0.^u-q*k0).*(p*u*k0.^u-q).*t.^2/factorial(2)...
  +(p*k0.^u-q*k0).*((p*u.*k0.^u-q).^2-p*u.*(u-1)*k0.^(u-1)./2).*t.^3/factorial(3));
% grid
  1 Commento
VBBV
VBBV il 31 Mag 2024
Modificato: VBBV il 31 Mag 2024

Use element wise matrix multiplication in the anonymous function as above. Also use a finite number of elements for vectors t and u as below

% grid
t = linspace(0,0.1,30);
u = linspace(0.3,0.9,30);
[T,U] = meshgrid(t,u);

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by